Skip to content

Commit 52a2874

Browse files
committed
Fix ambiguity error when includes file is referenced by multiple plugins
1 parent 2d66052 commit 52a2874

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

src/CompilablePlugin.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ internal void LoadPlugin(Action<CSharpPlugin> callback = null)
5151
return;
5252
}
5353

54+
if (!typeof(CSharpPlugin).IsAssignableFrom(type))
55+
{
56+
InitFailed("Main plugin class is not assignable to `CSharpPlugin`");
57+
return;
58+
}
59+
5460
CSharpPlugin plugin;
5561
try
5662
{
@@ -64,12 +70,12 @@ internal void LoadPlugin(Action<CSharpPlugin> callback = null)
6470
catch (TargetInvocationException invocationException)
6571
{
6672
Exception ex = invocationException.InnerException;
67-
InitFailed($"Unable to load {ScriptName}. {ex.ToString()}");
73+
InitFailed($"Unable to load {ScriptName}. {ex}");
6874
return;
6975
}
7076
catch (Exception ex)
7177
{
72-
InitFailed($"Unable to load {ScriptName}. {ex.ToString()}");
78+
InitFailed($"Unable to load {ScriptName}. {ex}");
7379
return;
7480
}
7581

src/CompilerService.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ private void EnqueueCompilation(Compilation compilation)
441441

442442
compilation.Started();
443443

444+
HashSet<string> includedFiles = new HashSet<string>();
445+
444446
List<CompilerFile> sourceFiles = new List<CompilerFile>();
445447
foreach (CompilablePlugin plugin in compilation.plugins)
446448
{
@@ -452,16 +454,25 @@ private void EnqueueCompilation(Compilation compilation)
452454
continue;
453455
}
454456

455-
foreach (var include in plugin.IncludePaths.Distinct())
457+
foreach (string include in plugin.IncludePaths.Distinct())
456458
{
457-
CompilerFile inc = new CompilerFile(include);
458-
if (inc.Data == null || inc.Data.Length == 0)
459+
if (includedFiles.Contains(include))
459460
{
460-
Log(LogType.Warning, $"Ignoring plugin {inc.Name}, file is empty");
461+
Log(LogType.Warning, $"Tried to include {include} but it has already been added to the compilation");
461462
continue;
462463
}
463-
Log(LogType.Info, $"Adding {inc.Name} to compilation project");
464-
sourceFiles.Add(inc);
464+
465+
CompilerFile includeFile = new CompilerFile(include);
466+
if (includeFile.Data == null || includeFile.Data.Length == 0)
467+
{
468+
Log(LogType.Warning, $"Ignoring plugin {includeFile.Name}, file is empty");
469+
continue;
470+
}
471+
472+
Log(LogType.Info, $"Adding {includeFile.Name} to compilation project");
473+
474+
sourceFiles.Add(includeFile);
475+
includedFiles.Add(include);
465476
}
466477

467478
Log(LogType.Info, $"Adding plugin {name} to compilation project");
@@ -470,7 +481,7 @@ private void EnqueueCompilation(Compilation compilation)
470481

471482
if (sourceFiles.Count == 0)
472483
{
473-
Log(LogType.Error, $"Compilation job contained no valid plugins");
484+
Log(LogType.Error, "Compilation job contained no valid plugins");
474485
compilations.Remove(compilation.id);
475486
compilation.Completed();
476487
return;

0 commit comments

Comments
 (0)