question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

flow sensitive typing for value cases

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jvasileffcommented, Sep 8, 2017

so I’m not going to be the one that closes this issue 😃

I totally lied. This has been duplicated by #7248. Closing.

1reaction
jvasileffcommented, Nov 16, 2016

For object values like null and red | green, the simple alternatives is Null and is \Ired |\Igreen work. In the case of null the alternative is no worse. And for red | green, I know typesafe use of subsets of enumerated cases isn’t common.

I presume we don’t want to use the type \Inull

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 for obj to be Integer, but this hasn’t come up in any code I’ve written.

unless someone can show me a truly compelling use-case.

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 😃.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found