No equivalence between `super` and `this` in a path, scala 2 disagrees
See original GitHub issueCompiler version
Scala 3.0.0-RC3
Minimized code
package tastytest
object SuperTypes {
class Foo {
final val foo: String = "Foo.foo" // must be widened type
}
class Bar extends Foo {
object A {
def unapply(a: Any) = Some[Bar.super.foo.type](Bar.this.foo)
}
def bar: Bar.super.foo.type = "" match { case A(x) => x }
}
}
Output
-- [E007] Type Mismatch Error: run/src-3/tastytest/SuperTypes.scala:12:62 ------
12 | def unapply(a: Any) = Some[Bar.super.foo.type](Bar.this.foo)
| ^^^^^^^^^^^^
| Found: (Bar.this.foo : String)
| Required: (Bar.super.foo : String)
Explanation
===========
I tried to show that
(Bar.this.foo : String)
conforms to
(Bar.super.foo : String)
but the comparison trace ended with `false`:
==> (Bar.this.foo : String) <: (Bar.super.foo : String)
==> (Bar.this.foo : String) <: (Bar.super.foo : String) (recurring)
==> (Bar.this : tastytest.SuperTypes.Bar) <: (Bar.super : tastytest.SuperTypes.Foo)
==> (Bar.this : tastytest.SuperTypes.Bar) <: (Bar.super : tastytest.SuperTypes.Foo) (recurring)
==> tastytest.SuperTypes.Bar <: (Bar.super : tastytest.SuperTypes.Foo) (left is approximated)
==> tastytest.SuperTypes.Bar <: (Bar.super : tastytest.SuperTypes.Foo) (recurring)
<== tastytest.SuperTypes.Bar <: (Bar.super : tastytest.SuperTypes.Foo) (recurring) = false
<== tastytest.SuperTypes.Bar <: (Bar.super : tastytest.SuperTypes.Foo) (left is approximated) = false
<== (Bar.this : tastytest.SuperTypes.Bar) <: (Bar.super : tastytest.SuperTypes.Foo) (recurring) = false
<== (Bar.this : tastytest.SuperTypes.Bar) <: (Bar.super : tastytest.SuperTypes.Foo) = false
==> String <: (Bar.super.foo : String) (left is approximated)
==> String <: (Bar.super.foo : String) (recurring)
==> String <: (Bar.super.foo : String) (recurring)
<== String <: (Bar.super.foo : String) (recurring) = false
<== String <: (Bar.super.foo : String) (recurring) = false
<== String <: (Bar.super.foo : String) (left is approximated) = false
<== (Bar.this.foo : String) <: (Bar.super.foo : String) (recurring) = false
<== (Bar.this.foo : String) <: (Bar.super.foo : String) = false
The tests were made under the empty constraint
1 error found
Expectation
Compiles like in Scala 2.13.5
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
A Scala Tutorial for Java Programmers
Inheritance and overriding All classes in Scala inherit from a super-class. When no super-class is specified, as in the Complex example of previous...
Read more >When to use the equals sign in a Scala method declaration?
I actually disagree pretty strongly with Daniel. I think the non-equal syntax should never be used. If your method is being exposed as...
Read more >Scala IO fix-up/overhaul · Issue #19 · scala/slip - GitHub
Feeling in the SLIP committee is that a Target that aimed to be the equivalent for output as Source is for input as...
Read more >A Scala Tutorial for Java Programmers
A basic knowledge of object-oriented programming, especially in Java, is assumed. ... there is no need to implement equivalent classes in the Scala...
Read more >Why I and my company have moved away from Scala. An ...
Scala could be the next super language if academics stop messing with it like ... but path equivalence is decided statically, so, there's...
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 Free
Top 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
I have no idea what’s going on here so please don’t count on me to fix that any time soon 😃.
Scala 2 errors on
Bar.super.foo
, per spec, but what isBar.super.foo.type
? IfFoo
definestype Oof = foo.type
, then Scala 3 is also fine withBar.super.Oof
. Is the type of a member effectively a member type? I’m recovering from covid shot nr 2, so it’s all a fog.