Skip to content

Commit 45b2a72

Browse files
Abort code generation when compilation errors occur, such as syntax problems.
1 parent 09c5c39 commit 45b2a72

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

src/Pure.DI.Core/Core/Semantic.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,17 @@ public bool IsAccessible(ISymbol symbol) =>
2020
{
2121
var typeInfo = semanticModel.GetTypeInfo(node, cancellationToken);
2222
var typeSymbol = typeInfo.Type ?? typeInfo.ConvertedType;
23-
if (typeSymbol is T symbol and not IErrorTypeSymbol)
23+
if (typeSymbol is not T symbol)
2424
{
25-
return (T)symbol.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
25+
return default;
2626
}
2727

28-
return default;
28+
if (symbol is IErrorTypeSymbol)
29+
{
30+
throw HandledException.Shared;
31+
}
32+
33+
return (T)symbol.WithNullableAnnotation(NullableAnnotation.NotAnnotated);
2934
}
3035

3136
public T GetTypeSymbol<T>(SemanticModel semanticModel, SyntaxNode node)

tests/Pure.DI.IntegrationTests/ErrorsAndWarningsTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,11 +2421,10 @@ public static void Main()
24212421
}
24222422
}
24232423
}
2424-
""".RunAsync(new Options(LanguageVersion.CSharp9));
2424+
""".RunAsync(new Options(LanguageVersion.CSharp9, CheckCompilationErrors: false));
24252425

24262426
// Then
24272427
result.Success.ShouldBeFalse(result);
2428-
result.Logs.Count(i => i.Id == LogId.ErrorTypeCannotBeInferred && i.Locations.FirstOrDefault().GetSource() == "repo").ShouldBe(1, result);
24292428
}
24302429

24312430
[Theory]

0 commit comments

Comments
 (0)