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

Error for `typeof(T?)` when `T` is a reference type #35001

Open
wants to merge 2 commits into
base: master
from

Conversation

@gafter
Copy link
Member

gafter commented Apr 16, 2019

Fixes #29894

@gafter gafter added this to the 16.1.P3 milestone Apr 16, 2019

@gafter gafter requested a review from dotnet/roslyn-compiler as a code owner Apr 16, 2019

@gafter gafter self-assigned this Apr 16, 2019

@gafter gafter added this to In Review in Compiler: Gafter Apr 16, 2019

@gafter

This comment has been minimized.

Copy link
Member Author

gafter commented Apr 16, 2019

@dotnet/roslyn-compiler May I please have a second review for this nullable fix?

object o6 = typeof(K<string?>); // 6
object o7 = typeof(K<int?>?); // 7, 8
object o8 = typeof(K<string?>?);// 9, 10, 11
}

This comment has been minimized.

Copy link
@jcouv

jcouv Apr 17, 2019

Member

nit: would it also be worth capturing behavior for generic type parameters? (T, TClass, TStruct)

@jcouv

jcouv approved these changes Apr 17, 2019

Copy link
Member

jcouv left a comment

LGTM Thanks (iteration 1)

// (13,25): error CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.
// _ = typeof(List<T?>);
Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(13, 25)
);
Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(13, 25));

This comment has been minimized.

Copy link
@AlekseyTs

AlekseyTs Apr 18, 2019

Contributor

)); [](start = 102, length = 3)

Consider preserving original formatting.

@@ -33220,13 +33226,18 @@ void M()

// https://github.com/dotnet/roslyn/issues/29894: should nullable reference types be disallowed in `typeof`?

This comment has been minimized.

Copy link
@AlekseyTs

AlekseyTs Apr 18, 2019

Contributor

// #29894: should nullable reference types be disallowed in typeof? [](start = 12, length = 108)

Can we remove this comment now?

@AlekseyTs
Copy link
Contributor

AlekseyTs left a comment

LGTM with a couple of suggestions (iteration 2).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.