method with singleton type mismatches same singleton type
See original GitHub issueAs the below example shows, a method that takes a singleton type Int(1)
cannot be applied with 1
.
scala> def id(x: 1): 1 = x
id: (x: Int(1))Int(1)
scala> id(1)
-- [E007] Type Mismatch Error: <console> -----------------------------------
6 |id(1)
| ^
| found: Int(1)
| required: Int(1)
|
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Strange type mismatch with a macro: found - Stack Overflow
Strange type mismatch with a macro: found: singleton type with underlying type A, required: A ... Which makes no sense to me: y.type...
Read more >Typetag of a singleton type - Google Groups
At least, it is according to the spec: "A singleton type is of the form p.type, where p is a path pointing to...
Read more >SIP-23 - Literal-based singleton types - Scala Documentation
A singleton type is of the form p.type . Where p is a path pointing to a value which conforms to scala.AnyRef ,...
Read more >Pattern match claims `x.type` is erased · Issue #12569 - GitHub
Spec says "A singleton type p.type. This type pattern matches only the value denoted by the path p (the eq method is used...
Read more >Making Singleton More Effective in Java - DZone
Want to learn more about when to use the singleton design pattern in Java? ... a ClassCastException will be thrown when the type...
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 have analyzed this a little.
What I have noticed is that in Typer.scala:1841 where the types are compared
it returns false when my code from the first example is run in the REPL, but it returns true if the example from @liufengyun is run (ie. w/o REPL).
Actually, in both cases both sides are equal (
ConstantType(Constant(4))
) however in the REPL, the two don’t refer to the same object in memory whereas otherwise they do. It seems that theTypeComparer
doesn’t return true unless they point to the same object in memory.My assumption is that the types are usually cached, but not between runs in the REPL. This is supported by the following snippet, which works in the REPL:
What I am unsure about is whether all types are always supposed to be cached and therefore the REPL needs to ensure that it re-uses types between runs (ie. several evaluated lines) or the
TypeComparer
should return true intopLevelSubType
if they are the same but don’t point to the same object.Thanks a lot! I’m actually mostly using the debugger to step through and try to make sense out of it 😃