Skip to content

Commit a83fcaa

Browse files
committed
#467: SelfContained does not work anymore since version 4.14.4
Added a case specific warning.
1 parent 7aea71e commit a83fcaa

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/CSScriptLib/src/CSScriptLib/Evaluator.Roslyn.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ SyntaxTree createTree(string code, string path) =>
486486
{
487487
IEnumerable<Diagnostic> failures = result.Diagnostics.Where(d => d.IsWarningAsError ||
488488
d.Severity == DiagnosticSeverity.Error);
489-
490489
var message = new StringBuilder();
491490
foreach (Diagnostic diagnostic in failures)
492491
{
@@ -514,6 +513,18 @@ SyntaxTree createTree(string code, string path) =>
514513
message.AppendLine($"{error_location}error {diagnostic.Id}: {diagnostic.GetMessage()}");
515514
}
516515

516+
bool cs0518_Object = failures.Any(x => x.Id == "CS0518" && x.GetMessage().Contains("'System.Object'"));
517+
bool cs0518_Void = failures.Any(x => x.Id == "CS0518" && x.GetMessage().Contains("'System.Void'"));
518+
bool cs0012_CoreLib = failures.Any(x => x.Id == "CS0012" && x.GetMessage().Contains("System.Private.CoreLib"));
519+
520+
if (cs0518_Object && cs0518_Void && cs0012_CoreLib && effectiveCodeKind == SourceCodeKind.Regular)
521+
{
522+
message.AppendLine();
523+
message.AppendLine("This error can be caused by Roslyn compilation using SourceCodeKind being set to Regular. " +
524+
"Try to specify SourceCodeKind.Script with the RoslynEvaluator.Compile(...) or set it " +
525+
"globally with `Globals.DefaultRoslynCompilationToScript = true`");
526+
}
527+
517528
var errors = message.ToString();
518529

519530
throw new CompilerException(errors);

0 commit comments

Comments
 (0)