Skip to content

Conversation

@AlekseyTs
Copy link
Contributor

No description provided.

@AlekseyTs
Copy link
Contributor Author

@akhera99, @CyrusNajmabadi, @dotnet/roslyn-ide Please review.

class Goo(int x, int {|Definition:$$y|})
{
public int y { get; } = [|y|];
public int z { get; } => [|y|];
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about the removals here? was that intentional/needed? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious about the removals here? was that intentional/needed?

I added dedicated test for this scenario. The property y declared above shadows the parameter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, gotcha. IMO, it would be better to leave the line in, but take off the [| |] around it (to make it clear that that 'y' is not considered a ref. But up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put the lines back as suggested

{
var updatedParameters = UpdateDeclaration(@struct.ParameterList.Parameters, signaturePermutation, CreateNewParameterSyntax);
return @struct.WithParameterList(@struct.ParameterList.WithParameters(updatedParameters).WithAdditionalAnnotations(changeSignatureFormattingAnnotation));
}
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could the above three 'if' statements be merged into one?

Syntax question. is 'ParameterList' added to TypeDeclSyntax, or only these three subclasses. If the latter, could we consider actually moving up to TypeDeclSyntax and having it always be null for interfaces. Or have interfaces allow parsing them out (for error recovery) and then report errors that it's not allowed there. feels like it would help prevent a bunch of duplication in consumption code. #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could the above three 'if' statements be merged into one?

At the moment we do not have WithParameterList API on a base class and I prefer to not add it because it wouldn't be appropriate for all types derived from that base.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment we do not have WithParameterList API on a base class and I prefer to not add it because it wouldn't be appropriate for all types derived from that base.

I'm totally fine with that for the current state of affairs. Can this be noted though for when we bring this to API review? I'd like to make an alternative case. But that's def not blocking this work now. Thanks! :)


primaryConstructor = typeSymbol.InstanceConstructors.FirstOrDefault(
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax);
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax or ClassDeclarationSyntax or StructDeclarationSyntax);
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi Feb 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax or ClassDeclarationSyntax or StructDeclarationSyntax);
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is TypeDeclarationSyntax);
Suggested change
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is RecordDeclarationSyntax or ClassDeclarationSyntax or StructDeclarationSyntax);
c => c.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is not ConstructorDeclarationSyntax);

Though, actually, this logic slightly worries me. Won't this return 'true' for the implicitly created constructor for a struct that does not have an actual primary constructor? Maybe we should say that the syntax has to both be the DeclSyntax And the decl syntax has a primary constructor? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to follow the pattern established for records. TypeDeclarationSyntax would include interfaces and this is not my intention.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Some questions/suggestions, and a slight concern. But nothing blocking at all.

@AlekseyTs AlekseyTs merged commit d91e6b5 into dotnet:features/PrimaryConstructors Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants