csharplang/meetings/2017/LDM-2017-03-28.md

48 lines
1.3 KiB
Markdown
Raw Normal View History

2017-04-06 01:03:55 +02:00
# C# Language Design Notes for Mar 28, 2017
## Agenda
2017-05-31 02:04:11 +02:00
Design some remaining 7.1 features
1. Fix pattern matching restriction with generics
2. Better best common type
2017-04-06 01:03:55 +02:00
2017-05-31 02:04:11 +02:00
# Fix pattern matching restriction with generics
2017-04-06 01:03:55 +02:00
Today `x as T` is allowed if
1. there is a reasonable relationship between the left and right type, or
2. one of them is an open type
2017-05-31 02:04:11 +02:00
But for the `is` operator we don't have the second. That means that we can't always replace uses of `as` followed by null check with an `is` with a type pattern.
2017-04-06 01:03:55 +02:00
Also, the restrictions are supposed to rule out only obviously useless cases, whereas some of these are demonstrably useful.
Let's allow it, look again if there are unexpected problems.
2017-05-31 02:04:11 +02:00
# Better best common type
2017-04-06 01:03:55 +02:00
Best common type should combine a value type with null literal to get a nullable value type.
``` c#
b1 ? 1 : b2 ? null : b3 ? 2 : default; // default is 0
b1 ? 1 : b2 ? default : b3 ? 2 : null; // default is null
b1 ? 1 : (b2 ? null : (b3 ? 2 : default)); // default is 0
b1 ? 1 : (b2 ? default : (b3 ? 2 : null)); // default is null
```
2017-05-31 02:04:11 +02:00
This is weird, but fine:
2017-04-06 01:03:55 +02:00
``` c#
M(1, default, null); // int?
```
Next step is trying to spec it. It's a bit complicated.
``` c#
M(myShort, myNullableInt, null); Should continue to infer int? , not short?
```