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.

No equivalence between `super` and `this` in a path, scala 2 disagrees

See original GitHub issue

Compiler 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:open
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Apr 30, 2021

I have no idea what’s going on here so please don’t count on me to fix that any time soon 😃.

0reactions
som-snyttcommented, Apr 30, 2021

Scala 2 errors on Bar.super.foo, per spec, but what is Bar.super.foo.type? If Foo defines type Oof = foo.type, then Scala 3 is also fine with Bar.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.

Read more comments on GitHub >

github_iconTop 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 >

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