flow sensitive typing for value cases
See original GitHub issueThe following does not compile:
String|Absent foo<Absent=Nothing>
(Float|Integer|Absent input)
given Absent satisfies Null
=> switch (input)
case (is Float) "f"
case (is Integer) "i"
case (null) input;
// error: specified expression type must be assignable to declared return type:
// 'String|Float|Integer|Absent' is not assignable to 'String|Absent'
Replacing case (null)
with else
eliminates the error at the expense of readability. case (is Null)
also works.
I presume we don’t want to use the type \Inull
, but I think subtracting Float
and Integer
(as is done with else
) would be nice here, making input
Absent
.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Flow-sensitive typing - Wikipedia
In programming language theory, flow-sensitive typing is a type system where the type of an expression depends on its position in the control...
Read more >Flow-Sensitive Typing - Sorbet
Sorbet implements a control flow-sensitive type system. It models control flow through a program and uses it to track the program's types more...
Read more >Flow-Sensitive Type Qualifiers
Standard type systems are flow-insensitive, meaning a value's type is the same everywhere. However, many impor- tant program properties are flow-sensitive.
Read more >Implementing a Language with Flow-Sensitive and Structural ...
The Whiley language implements a flow-sensitive and structural type system on the JVM. This permits variables to be declared implicitly, have multiple types ......
Read more >On Flow-Sensitive Security Types - Page has been moved
Abstract. This article investigates formal properties of a family of seman- tically sound flow-sensitive type systems for tracking information.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I totally lied. This has been duplicated by #7248. Closing.
For object values like
null
andred | green
, the simple alternativesis Null
andis \Ired |\Igreen
work. In the case ofnull
the alternative is no worse. And forred | green
, I know typesafe use of subsets of enumerated cases isn’t common.I’m not entirely sure why I said that. We’d be narrowing, not inferring.
For literal values like
case (7 | 13) { processSpecialNum(obj); }
, it would be useful forobj
to beInteger
, but this hasn’t come up in any code I’ve written.I haven’t been able to convince myself that this feature would be useless, so I’m not going to be the one that closes this issue 😃.