Open kpodsiad opened 9 months ago
The result type of foo[1 | 2 | 3](2)
is an inferred type and is therefore widened to Int
. That's a very carefully calibrated behavior which is according to spec. Any change would open a big rabbit hole. Not saying someone should not try it, ever, but this is way to much to ask in an issue and is certainly not a bug.
It's not a big deal as user can provide an explicit type and it'll work. I was just a bit surprised to see difference between foo
and foo2
, that in the second case it's not widened to Int
. Thanks for explanation!
Compiler version
3.3.1
Minimized code
or
Output
or the one from repl.
Expectation
Return type of
foo(2)
isInt
and it's ok, butfoo[1 | 2 | 3](2)
should have1 | 2 | 3
. At least it is incosistent withfoo2[1 | 2 | 3](2)
havingOption[1 | 2 | 3]