You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
isInstanceOf has difference when run in compile time vs runtime. Here is an sbt example where a valid subtype isn't detected, when passed as method arg.
Compiler version
3.0.1-RC1
Minimized code
typeTimeframe="1m"|"2m"|"1H"@main defmain(input: String) =valisTimeframe= input.isInstanceOf[Timeframe]
valoneM:String="1m"
println(s"input is of Timeframe: $isTimeframe")
println(s"1m is of Timeframe: ${oneM.isInstanceOf[Timeframe]}")
Output
Running with 1m which is a valid Timeframe type.
sbt:scala3-simple> run 1m
[info] running main 1m
input is of Timeframe:false
1m is of Timeframe:true
Expectation
sbt:scala3-simple> run 1m
[info] running main 1m
input is of Timeframe: true
1m is of Timeframe: true
Original motivation for doing this was to check if an input from untrusted source is of the specified type.
The text was updated successfully, but these errors were encountered:
So somehow the compiler also knows about literals in the code being at the callsite, when you write code like this
typeTimeframe="1m"|"2m"|"1H"defok(input: String) =valoneMinute:String="1m"
println(s"input: $input is of Timeframe: ${input.isInstanceOf[Timeframe]}")
println(s"1m is of Timeframe: ${oneMinute.isInstanceOf[Timeframe]}")
@main defmain(input: String) =
ok("1H")
ok(input)
This is also a bit troubling.
sbt:scala3-simple> run 1m
input: 1H is of Timeframe: true
1m is of Timeframe: true
input: 1m is of Timeframe: false
1m is of Timeframe: true
odersky
added a commit
to dotty-staging/dotty
that referenced
this issue
Jun 12, 2021
Uh oh!
There was an error while loading. Please reload this page.
isInstanceOf
has difference when run in compile time vs runtime. Here is an sbt example where a valid subtype isn't detected, when passed as method arg.Compiler version
3.0.1-RC1
Minimized code
Output
Running with
1m
which is a validTimeframe
type.Expectation
Original motivation for doing this was to check if an input from untrusted source is of the specified type.
The text was updated successfully, but these errors were encountered: