Skip to content

BUG: TermRefs with uninstantiated type variables get incorrect signatures #822

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
wants to merge 2 commits into from

Conversation

smarter
Copy link
Member

@smarter smarter commented Oct 8, 2015

This PR should not be merged, it demonstrates a bug.

After frontend, pickleinf.scala looks like:

package <empty>.type {
  class Bar[N]() extends java.lang.Object() { 
    type Bar$$N
    private[this] type N = Bar$$N
    def bar(name: Bar.this.Bar$$N, dummy: scala.Int): Bar.this.Bar$$N = name
    def bar$default$2: scala.Int = 42
  }
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends java.lang.Object() { this: Test.type => 
    def test(): scala.Unit = {
      {
        {
          val $1$: Bar[scala.Int] = new Bar[scala.Int]()
          $1$.bar(10, $1$.bar$default$2)
        }
        ()
      }
    }
  }
}

The bug only manifests itself after unpickling, but the problem is already present when we pickle the type:

sel: Select(Ident($1$),bar)
sel.tpe: TermRef(TermRef(NoPrefix,$1$),bar)
sel.tpe.widen: MethodType(List(name, dummy), List(TypeRef(TermRef(NoPrefix,$1$),Bar$$N), TypeRef(TermRef(ThisType(TypeRef(NoPrefix,<root>)),scala),Int)), TypeRef(TermRef(NoPrefix,$1$),Bar$$N))
sel.tpe.signature: Signature(List(java.lang.Object, scala.Int),java.lang.Object)

Notice that in the signature we get java.lang.Object instead of scala.Int for the first parameter and the return type, this happens because the signature is computed and cached before N is instantiated to Int.
CC @odersky

@smarter
Copy link
Member Author

smarter commented Oct 8, 2015

I guess the problem is that we try to take the signature of bar at a point where the type of its first parameter is an uninstantiated type variable.

> run -Xprint-types -Ytest-pickler -Ystop-after:pickler tests/pos/pickleinf.scala
[error] (no source file, offset = 0): error: value of type
        <notype> does not take parameters
@smarter
Copy link
Member Author

smarter commented Oct 8, 2015

I managed to reproduce the problem in master, I'll update this PR and the description.

@smarter smarter force-pushed the bug/pickle-inference branch from 7278f5b to 29e8ec9 Compare October 8, 2015 17:10
@smarter smarter changed the title BUG: unpickled type is incorrect after tweaking inference BUG: TermRefs with uninstantiated type variables get incorrect signatures Oct 8, 2015
@smarter
Copy link
Member Author

smarter commented Oct 8, 2015

I think this particular issue could be fixed if EtaExpansion#lift would call fullyDefinedType, otherwise we can get a ValDef with an uninstantiated type parameter which should not be allowed.

smarter added a commit to smarter/dotty that referenced this pull request Oct 9, 2015
@smarter
Copy link
Member Author

smarter commented Oct 9, 2015

Proposed fix at #823.

smarter added a commit to smarter/dotty that referenced this pull request Oct 19, 2015
@smarter smarter closed this in #823 Oct 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant