-
Notifications
You must be signed in to change notification settings - Fork 292
Fix ConstructorProvider.Initializer not populated for custom constructors #7855
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 8, 2025 22:20
...ft.TypeSpec.Generator/test/Providers/NamedTypeSymbolProviders/ConstructorInitializerTests.cs
Outdated
Show resolved
Hide resolved
…established pattern Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
...ft.TypeSpec.Generator/test/Providers/NamedTypeSymbolProviders/ConstructorInitializerTests.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
…eneratorAsync and remove Setup method Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 9, 2025 19:00
...ft.TypeSpec.Generator/test/Providers/NamedTypeSymbolProviders/ConstructorInitializerTests.cs
Outdated
Show resolved
Hide resolved
…d refactor to use ModelProvider.CustomCodeView Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 9, 2025 19:21
...rator/Microsoft.TypeSpec.Generator/test/TestResults/_pkrvmfkh1xnbeme_2025-07-09_18_48_02.trx
Outdated
Show resolved
Hide resolved
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 9, 2025 19:31
JoshLove-msft
approved these changes
Jul 9, 2025
jorgerangel-msft
approved these changes
Jul 9, 2025
...ers/TestData/CustomConstructorWithBaseInitializerShouldHaveInitializerPopulated/BaseClass.cs
Outdated
Show resolved
Hide resolved
…izerTests to follow established pattern Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 9, 2025 20:01
...st/Providers/ConstructorProviders/ConstructorInitializerTests/ConstructorInitializerTests.cs
Outdated
Show resolved
Hide resolved
…ConstructorProviders and TestData under ConstructorProviders/TestData/ConstructorInitializerTests Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copilot finished work on behalf of
JoshLove-msft
July 9, 2025 20:10
JoshLove-msft
approved these changes
Jul 9, 2025
jorgerangel-msft
approved these changes
Jul 9, 2025
jsquire
approved these changes
Jul 9, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
ConstructorProvider.Initializer
property was not being populated when parsing custom constructors with initializers (: this(...)
or: base(...)
). This meant that constructor initializer information was lost during code generation.Problem
When custom constructors contained initializers like:
The
ConstructorProvider.Signature.Initializer
property would benull
instead of containing the initializer information.Root Cause
The issue was in
NamedTypeSymbolProvider.BuildConstructors()
method which createsConstructorSignature
objects from RoslynIMethodSymbol
data. The method was not extracting constructor initializer information from the syntax tree, so theInitializer
parameter was always defaulting tonull
.Solution
ExtractConstructorInitializer
method - Analyzes constructor syntax using Roslyn to detect and extract initializer information fromConstructorDeclarationSyntax
BuildConstructors
- Now passes the extracted initializer to theConstructorSignature
constructorValueExpression
types for both literals and identifiersthis
initializers,base
initializers, and constructors without initializersTesting
Added comprehensive test cases in
ConstructorInitializerTests
:CustomConstructorWithThisInitializerShouldHaveInitializerPopulated
- Validates: this(...)
initializersCustomConstructorWithBaseInitializerShouldHaveInitializerPopulated
- Validates: base(...)
initializersCustomConstructorWithoutInitializerShouldHaveNullInitializer
- Ensures constructors without initializers still work correctlyAll tests pass, including existing test suites (41 NamedTypeSymbolProvider tests, 2 ConstructorProvider tests).
Fixes #6717.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
aka.ms
curl -I -sSL --retry 5 --retry-delay 2 --connect-timeout 15 REDACTED
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.