-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Span<RefStruct> is permitted through an implicitly-typed variable #25038
Comments
/cc @VSadov |
I think the second case is where it is a pointer for compat reasons. What is the type of y ? |
is actually emitted. See the example in sharplab. AFAIK stackalloc only returns a pointer when it's directly in a local decl initializer. |
A bug then :) |
I really wished we hadn't change stackalloc default type based on the context it's being used. as far as I know the motivating example was that in a ternary we didn't want to cast either of operands to Span, var x = size < 100 ? stackalloc int[size] : (Span<int>)new int[100]; // x is Span And that stackalloc in local decl initializers already produce a pointer var x = stackalloc int[size]; // x is pointer So we changed the default type to Span anywhere except for the above case. We could address the problem by target typing the whole ternary expression if it fails to cast either of operands to each other. Span<int> x = size < 100 ? stackalloc int[size] : new int[100]; But now it's a breaking change because the above code works with Note that that could be useful in other places too, IEnumerable<StatemnetSyntax> x = statementSyntax is Block block
? block.Statements
: new [] { statemnetSyntax }; // No cast required, Would it worth it to open an issue in csharplang or it's too late for this? |
I'd say it is worth taking the breaking change. Will create a PR and see what others might say about this. |
@OmarTawfik Do you mean fixing the bug in the OP worth the breaking change or my proposal above? (note: that proposal would make this bug irrelevant because you need to specify the type anyways) |
I meant fixing the original bug. |
@alrz closing as my PR was merged. Please tag me if you've other concerns. |
Version Used: 37e7192 head of
features/compilers
Steps to Reproduce:
Expected Behavior: error in both cases
Actual Behavior: error only if
S
is spelt outThe text was updated successfully, but these errors were encountered: