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.

infer "of" narrowing

See original GitHub issue

Let’s face it: it’s totally weird that this is well-typed:

alias Bool => \Itrue|\Ifalse;
void fun(Bool bool) {}
Boolean t = true;
fun(t of Bool);

But this is not:

alias Bool => \Itrue|\Ifalse;
void fun(Bool bool) {}
Boolean t = true;
fun(t);

In such cases, instead of producing an error, we could, completely safely and reasonably, just infer the of Bool bit. I’m conflicted about that because while it works perfectly nicely here, I guess it would create the expectation in the user’s head that \Itrue|\Ifalse and Boolean are the same type, which is an expectation that is violated as soon as these types are used as type arguments. (A List<Boolean> is not a List<\Itrue|\Ifalse> in Ceylon!

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
gavinkingcommented, Feb 28, 2016

Even if the compiler didn’t infer the of Bool, it could still generate an error message which suggests it as a possible fix!

0reactions
jvasileffcommented, Feb 9, 2017

Ah, that’s the one. It would be nice to dial it back a bit for refinement:

class A() {
    shared \Itrue | \Ifalse foo() => true;
}
class B() extends A() {
    shared Boolean foo() => true;
    // type of member must be assignable to type of refined member 'foo' in 'A':
    // the assigned type 'Boolean' is covered by, but not assignable to, the type
    // 'true|false' (explicitly narrow assigned expression using 'of true|false')
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Narrowing - TypeScript
(The latter has the advantage that TypeScript infers a narrow literal boolean type true , while inferring the first as type boolean .)...
Read more >
Narrowing: Meaning, Examples & Types | StudySmarter
Narrowing is a type of semantic change in which the meaning of a word becomes less generalised over time. Narrowing may also be...
Read more >
TypeScript type inference/narrowing challenge - Stack Overflow
I'd like to remove the need to explicitly narrow the type of the message passed to the message handler (where /*REMOVE THIS TYPE...
Read more >
Narrowing Types in TypeScript - Formidable Labs
Type narrowing is just what it sounds like—narrowing down a general ... is clever enough to infer the narrowing from our conditional logic....
Read more >
Inverse Narrowing for the Inductive Inference of Functional ...
Inverse Narrowing for the Inductive Inference of Functional Logic Programs1. J. Hernandez-Orallo & M.J. Ramirez-Quintana. DSIC, Universitat Politècnica de ...
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