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

Champion "default" expression (C# 7.1) #102

Open
gafter opened this Issue Feb 14, 2017 · 5 comments

Comments

Projects
None yet
4 participants
@gafter
Member

gafter commented Feb 14, 2017

See also dotnet/roslyn#7737
A working implementation was merged to master branch and is now in C# 7.1.

LDM history:

@gafter gafter changed the title from "default" expression to Champion "default" expression Feb 15, 2017

@gafter gafter added this to the 7.1 candidate milestone Feb 21, 2017

@jcouv

This comment has been minimized.

Show comment
Hide comment

@jcouv jcouv changed the title from Champion "default" expression to Champion "default" expression (C# 7.1) Jun 5, 2017

@franzalex

This comment has been minimized.

Show comment
Hide comment
@franzalex

franzalex Oct 7, 2017

@gafter Can you please fix the broken links in your post?

franzalex commented Oct 7, 2017

@gafter Can you please fix the broken links in your post?

@odalet

This comment has been minimized.

Show comment
Hide comment
@odalet

odalet Jan 11, 2018

I've noted that the following code does not compile (I'm using VS2017 15.5.2); I suspect there is a good reason for it; however I suppose it's worth mentioning it:

        public static (TR, TL) ToTuple<TR, TL>(this Either<TR, TL> source) =>
            source.IsRight ? (source.Right, default) : (default, source.Left);

It says that there is no conversion between (TR, default) and (default, TL); and this reminds me of the similar error we get when we need casting at leat one arm to a common base type... Similarly here, I just need to qualify one arm with a default(TL|TR) explicitely, not both...
However, I wonder whether, in this case, the type inference system could match on the return type?

odalet commented Jan 11, 2018

I've noted that the following code does not compile (I'm using VS2017 15.5.2); I suspect there is a good reason for it; however I suppose it's worth mentioning it:

        public static (TR, TL) ToTuple<TR, TL>(this Either<TR, TL> source) =>
            source.IsRight ? (source.Right, default) : (default, source.Left);

It says that there is no conversion between (TR, default) and (default, TL); and this reminds me of the similar error we get when we need casting at leat one arm to a common base type... Similarly here, I just need to qualify one arm with a default(TL|TR) explicitely, not both...
However, I wonder whether, in this case, the type inference system could match on the return type?

@jcouv

This comment has been minimized.

Show comment
Hide comment
@jcouv

jcouv Jan 11, 2018

Member

@odalet From a quick check at the spec for conditional expressions, I see that the return type of cond ? x : y is always either the type of x or the type of y.
But in your example, (source.Right, default) or (default, source.Left) by themselves (absent the context of a conditional) don't have determinable types.
In C#, type information for inference is not completely free-flowing, it only flows certain ways.

Member

jcouv commented Jan 11, 2018

@odalet From a quick check at the spec for conditional expressions, I see that the return type of cond ? x : y is always either the type of x or the type of y.
But in your example, (source.Right, default) or (default, source.Left) by themselves (absent the context of a conditional) don't have determinable types.
In C#, type information for inference is not completely free-flowing, it only flows certain ways.

@odalet

This comment has been minimized.

Show comment
Hide comment
@odalet

odalet Jan 14, 2018

Thanks for pointing this. It makes sense. Maybe, at one time in the future, the C# compiler could infer some type information from lvalues (as Rust does)

odalet commented Jan 14, 2018

Thanks for pointing this. It makes sense. Maybe, at one time in the future, the C# compiler could infer some type information from lvalues (as Rust does)

@jcouv jcouv referenced this issue Aug 8, 2018

Open

Test plan for "target-typed new" #28489

6 of 39 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment