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

GetTypeInfo returns TypeInfo with null as Type for ImplicitObjectCreationExpression inside CollectionExpression #70041

Closed
csaba-sagi-sonarsource opened this issue Sep 20, 2023 · 7 comments
Assignees
Labels
Area-Compilers Feature - Collection Expressions Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@csaba-sagi-sonarsource
Copy link

Version Used:

Steps to Reproduce:

Call semanticModel.GetTypeInfo for the ImplicitObjectCreationExpression from the snippet below.

class SomeClass
{
    private static Line[] SomeMethod() => [new(0)];

    private class Line
    {
        public Line(int length)
        {
        }
    }
}

Expected Behavior:
The type should be correctly retrieved.
Actual Behavior:
The type is null.

@CyrusNajmabadi
Copy link
Member

This is correct, an implicit objet has no type on it's own. it needs a target type it is converted to to actually determine what type it is. Check TypeInfo.ConvertedType instead.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 20, 2023
@CyrusNajmabadi CyrusNajmabadi added Question Resolution-Answered The question has been answered and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 20, 2023
@csaba-sagi-sonarsource
Copy link
Author

csaba-sagi-sonarsource commented Sep 21, 2023

@CyrusNajmabadi
Yes, and for the aforementioned snippet TypeInfo.ConvertedType is null too.

Also, what I would like to mention is that Type is not null for ImplicitObjectCreationExpression in the following snippet:

public record struct RecordStruct
{
    private class Line
    {
        public int Value;
    }

    public Line Create() => new() { Value = 1 };
}

I expect the behaviour to be the same for both calls.

@csaba-sagi-sonarsource
Copy link
Author

IDK if you will get the notification @CyrusNajmabadi since the issue is closed.
So, I tagged you. Sorry in case I created noise.

@CyrusNajmabadi
Copy link
Member

reactivating for compiler investigation.

@CyrusNajmabadi CyrusNajmabadi added untriaged Issues and PRs which have not yet been triaged by a lead and removed Question Resolution-Answered The question has been answered labels Sep 21, 2023
@jcouv
Copy link
Member

jcouv commented Sep 25, 2023

This was fixed as part of #69852 which includes multiple tests verifying that:

  1. the .Type is null
  2. the .ConvertedType is the proper/non-null converted type

@jcouv jcouv closed this as completed Sep 25, 2023
@jcouv jcouv added the Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented label Sep 25, 2023
@jcouv jcouv added this to the 17.8 milestone Sep 25, 2023
@jcouv jcouv self-assigned this Sep 25, 2023
@jcouv jcouv added Feature - Collection Expressions and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 25, 2023
@csaba-sagi-sonarsource
Copy link
Author

@jcouv,

Out of curiosity, can you tell me why Type is not null for the second snippet I posted and why it is planned to be null for the first one?

@sebastien-marichal
Copy link

Hello @jcouv,

I tested with the latest preview version of Visual Studio (Preview 5) and am still facing the same issue. ConvertedType returns null for ImplicitObjectCreationExpression in the snippet provided by @csaba-sagi-sonarsource.

Is the fix in #69852 has been released yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Collection Expressions Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

4 participants