-
Notifications
You must be signed in to change notification settings - Fork 225
Closed
Labels
recordsIssues related to records.Issues related to records.
Description
Consider the following example:
dynamic d = "hello";
(int, int) r = (d, 4);
There are two possible inferred types for the record literal.
- We might choose to infer this as
(dynamic, int)
- In this case this code is a static error, since neither type is
dynamic
, and the RHS type is not a subtype of the LHS type.
- In this case this code is a static error, since neither type is
- We might choose to infer this as
(int, int)
- In this case this code is a runtime error, since there must be an implicit cast added to cast
d
toint
before constructing the record.
- In this case this code is a runtime error, since there must be an implicit cast added to cast
Which do we intend?
In general, I'm not keen on adding more implicit downcasts. I'd rather the user make the cast explicit here.
We do push casts inwards for list literals however:
dynamic d = "hello";
List<int> l = [d];
fails at runtime, not statically (as it must, since we prefer the context type for nominal types, unlike the structural types).
cc @munificent @eernstg @lrhn @jakemac53 @natebosch @stereotype441 @kallentu @chloestefantsova @johnniwinther @scheglov @srawlins
Metadata
Metadata
Assignees
Labels
recordsIssues related to records.Issues related to records.