Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit field initialization in struct constructors #59788

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b2ba13b
WIP
RikkiGibson Feb 26, 2022
e167c09
Fix bugs. Update semantic tests.
RikkiGibson Mar 1, 2022
741403b
Fix remaining semantic tests
RikkiGibson Mar 2, 2022
3fbe7e6
Fix more tests
RikkiGibson Mar 2, 2022
c1b4562
Address most prototype comments
RikkiGibson Mar 2, 2022
e942cad
PROTOTYPE -> TODO
RikkiGibson Mar 2, 2022
ffc6125
don't give use site diagnostics for now
RikkiGibson Mar 3, 2022
5f23f47
Merge branch 'main' of github.com:dotnet/roslyn into struct-definite-…
RikkiGibson Mar 3, 2022
c0d76f2
Address feedback
RikkiGibson Mar 8, 2022
24159b6
Update src/Compilers/CSharp/Portable/FlowAnalysis/DefiniteAssignment.cs
RikkiGibson Mar 8, 2022
e738e9b
Address feedback
RikkiGibson Mar 8, 2022
3c3bcca
fix CI errors
RikkiGibson Mar 9, 2022
87422e8
WIP: use isDisabledByDefault instead of isSuppressed
RikkiGibson Mar 9, 2022
0fe879e
fix isEnabledByDefault
RikkiGibson Mar 10, 2022
8453dc1
Make GetIsEnabledByDefault abstract
RikkiGibson Mar 10, 2022
82f9ebc
Reduce space-only differences. Adjust nullable test.
RikkiGibson Mar 10, 2022
2bf7246
revert unnecessary change
RikkiGibson Mar 11, 2022
59e1ce5
Add static to CSharpTestBase.ReportStructInitializationWarnings
RikkiGibson Mar 11, 2022
db94a69
Don't call RootSlot when searching for field in 'this'
RikkiGibson Mar 14, 2022
b52b2d9
Address more feedback
RikkiGibson Mar 14, 2022
8f64d08
Update feature name in tests
RikkiGibson Mar 15, 2022
71a1d06
fix syntax error
RikkiGibson Mar 15, 2022
16b2c95
WIP
RikkiGibson Mar 16, 2022
3059241
Merge branch 'main' of github.com:dotnet/roslyn into struct-definite-…
RikkiGibson Mar 16, 2022
a55b38a
WIP
RikkiGibson Mar 17, 2022
2b546b4
Fix tests
RikkiGibson Mar 17, 2022
8c3d78a
Combine LangVersion with UseDef/Unassigned diagnostics. Update some t…
RikkiGibson Mar 17, 2022
1da2b31
Fix tests. Adjust message. Adjust assert.
RikkiGibson Mar 18, 2022
591e51c
Merge branch 'release/dev17.3' of github.com:dotnet/roslyn into struc…
RikkiGibson Mar 18, 2022
18bcab6
fix release build
RikkiGibson Mar 18, 2022
e16572c
Address prototype. Move error codes for now.
RikkiGibson Mar 18, 2022
307fcab
Update ErrorFacts.Generated.cs
RikkiGibson Mar 18, 2022
4c13809
Address feedback. Make diagnostic messages consistent.
RikkiGibson Mar 21, 2022
0bb7707
Merge branch 'release/dev17.3' of github.com:dotnet/roslyn into struc…
RikkiGibson Mar 26, 2022
6bcda83
Address feedback and pack error codes
RikkiGibson Mar 26, 2022
99fad4e
Merge branch 'release/dev17.3' of github.com:dotnet/roslyn into struc…
RikkiGibson Mar 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Compilers/CSharp/Portable/CSharpResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -6691,6 +6691,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="IDS_FeatureLineSpanDirective" xml:space="preserve">
<value>line span directive</value>
</data>
<data name="IDS_FeatureImplicitInitializationInStructConstructors" xml:space="preserve">
RikkiGibson marked this conversation as resolved.
Show resolved Hide resolved
<value>implicit initialization in struct constructors</value>
</data>
<data name="ERR_LineSpanDirectiveInvalidValue" xml:space="preserve">
<value>The #line directive value is missing or out of range</value>
</data>
Expand Down
8 changes: 4 additions & 4 deletions src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ private void CompileMethod(
}

var unusedDiagnostics = DiagnosticBag.GetInstance();
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, initializerStatements, unusedDiagnostics, requireOutParamsAssigned: false);
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, initializerStatements, unusedDiagnostics, out _, requireOutParamsAssigned: false);
DiagnosticsPass.IssueDiagnostics(_compilation, initializerStatements, BindingDiagnosticBag.Discarded, methodSymbol);
unusedDiagnostics.Free();
}
Expand Down Expand Up @@ -1077,7 +1077,7 @@ processedInitializers.AfterInitializersState is null &&
// Flow analysis over the initializers is necessary in order to find assignments to fields.
// Bodies of implicit constructors do not get flow analysis later, so the initializers
// are analyzed here.
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, requireOutParamsAssigned: false);
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, out _, requireOutParamsAssigned: false);
}

// In order to get correct diagnostics, we need to analyze initializers and the body together.
Expand All @@ -1089,7 +1089,7 @@ processedInitializers.AfterInitializersState is null &&
{
// These analyses check for diagnostics in lambdas.
// Control flow analysis and implicit return insertion are unnecessary.
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, requireOutParamsAssigned: false);
DefiniteAssignmentPass.Analyze(_compilation, methodSymbol, analyzedInitializers, diagsForCurrentMethod.DiagnosticBag, out _, requireOutParamsAssigned: false);
DiagnosticsPass.IssueDiagnostics(_compilation, analyzedInitializers, diagsForCurrentMethod, methodSymbol);
}
}
Expand Down Expand Up @@ -1122,7 +1122,7 @@ processedInitializers.AfterInitializersState is null &&
BoundBlock flowAnalyzedBody = null;
if (body != null)
{
flowAnalyzedBody = FlowAnalysisPass.Rewrite(methodSymbol, body, diagsForCurrentMethod.DiagnosticBag, hasTrailingExpression: hasTrailingExpression, originalBodyNested: originalBodyNested);
flowAnalyzedBody = FlowAnalysisPass.Rewrite(methodSymbol, body, compilationState, diagsForCurrentMethod, hasTrailingExpression: hasTrailingExpression, originalBodyNested: originalBodyNested);
}

bool hasErrors = _hasDeclarationErrors || diagsForCurrentMethod.HasAnyErrors() || processedInitializers.HasErrors;
Expand Down
17 changes: 17 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/DiagnosticBagExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode c
return info;
}

/// <summary>
/// Add a diagnostic to the bag.
/// </summary>
/// <param name="diagnostics"></param>
/// <param name="code"></param>
/// <param name="location"></param>
/// <param name="isSuppressed"></param>
/// <param name="args"></param>
/// <returns></returns>
RikkiGibson marked this conversation as resolved.
Show resolved Hide resolved
internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, bool isSuppressed, params object[] args)
{
var info = new CSDiagnosticInfo(code, args);
var diag = new CSDiagnostic(info, location, isSuppressed);
diagnostics.Add(diag);
return info;
}

internal static CSDiagnosticInfo Add(this DiagnosticBag diagnostics, ErrorCode code, Location location, ImmutableArray<Symbol> symbols, params object[] args)
{
var info = new CSDiagnosticInfo(code, args, symbols, ImmutableArray<Location>.Empty);
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/CSharp/Portable/Errors/MessageID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ internal enum MessageID

IDS_FeatureCacheStaticMethodGroupConversion = MessageBase + 12816,
IDS_FeatureRawStringLiterals = MessageBase + 12817,
IDS_FeatureImplicitInitializationInStructConstructors = MessageBase + 12818,
RikkiGibson marked this conversation as resolved.
Show resolved Hide resolved
}

// Message IDs may refer to strings that need to be localized.
Expand Down Expand Up @@ -360,6 +361,7 @@ internal static LanguageVersion RequiredVersion(this MessageID feature)
case MessageID.IDS_FeatureListPattern: // semantic check
case MessageID.IDS_FeatureCacheStaticMethodGroupConversion: // lowering check
case MessageID.IDS_ParameterNullChecking: // syntax check
case MessageID.IDS_FeatureImplicitInitializationInStructConstructors: // semantic check
return LanguageVersion.Preview;

// C# 10.0 features.
Expand Down
Loading