Skip to content

opaque type selects different method with -from-tasty #11819

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bishabosha opened this issue Mar 19, 2021 · 5 comments
Closed

opaque type selects different method with -from-tasty #11819

bishabosha opened this issue Mar 19, 2021 · 5 comments

Comments

@bishabosha
Copy link
Member

Compiler version

3.0.0-RC1

Minimized code

package opaquetypes

object `package`:

  opaque type Foo = Double

  object Bar:

    class Baz(val i: Foo):
      def foo(that: Any): Boolean = that match
        // `Double.==` selected from source; `Any.==` selected `-from-tasty`
        case that1 @ (_: Baz) => Baz.this.i == that1.i
        case _ => true

Expectation

Double.== should also be selected with -from-tasty, the issue arises when if you actually select Double.== in unpickling then the checker does not expect it

@bishabosha
Copy link
Member Author

bishabosha commented Mar 19, 2021

@smarter this one is a problem because at the point of pickling, Baz.this.i.== resolves to the symbol Double.==, but at the point of unpickling qualType.findMember("==") would find Any.==, same with TreeChecker.

I would think TreeChecker should not find Any.==, this makes it a problem to encode selecting from an opaque type with SELECTin in #11210

Noteworthy is that when compiling from source TreeChecker has no problem with Double.==

@smarter
Copy link
Member

smarter commented Mar 19, 2021

Shouldn't findMember find both and pick the one from Double since it has the correct signature?

@bishabosha
Copy link
Member Author

bishabosha commented Mar 19, 2021

@smarter no, it gets NoDenotation

// compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
def accessibleDenot(qualType: Type, name: Name, sig: Signature, target: Name) = {
  val pre = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
  val d = qualType.findMember(name, pre).atSignature(sig, target)
  val denot =
    if (!d.symbol.exists || d.symbol.isAccessibleFrom(pre)) d
    else qualType.findMember(name, pre, excluded = Private).atSignature(sig, target)
  report.echo(i"$qualType.$name unpickle from SELECT is denot $denot (sig is $sig)")
  denot
}

we get the log message

(Baz.this.i : opaquetypes.Foo).== unpickle from SELECT is denot NoDenotation (sig is Signature(List(scala.Double),scala.Boolean))

@smarter
Copy link
Member

smarter commented Mar 19, 2021

I think https://github.com/dotty-staging/dotty/commits/thisType-check fixes the problem, can you double-check and take care of integrating it in your PR (sameThis should probably be a method in ThisType...).

@bishabosha
Copy link
Member Author

I think https://github.com/dotty-staging/dotty/commits/thisType-check fixes the problem, can you double-check and take care of integrating it in your PR (sameThis should probably be a method in ThisType...).

I just tried and it worked, very cool

@bishabosha bishabosha self-assigned this Mar 19, 2021
bishabosha added a commit to dotty-staging/dotty that referenced this issue Mar 19, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
bishabosha added a commit to dotty-staging/dotty that referenced this issue Mar 19, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
bishabosha added a commit to dotty-staging/dotty that referenced this issue Mar 22, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
bishabosha added a commit to dotty-staging/dotty that referenced this issue Mar 23, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
michelou pushed a commit to michelou/scala3 that referenced this issue Mar 25, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
michelou pushed a commit to michelou/scala3 that referenced this issue Apr 14, 2021
We cannot assume that all equivalent ThisType have the same
identity (even with hash-consing, they can be constructed from different
but equivalent TypeRefs).

Co-authored-by: Guillaume Martres <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants