Skip to content
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

instantiate gets confused if tvar is inferred to be a refinement type whose parent is a refinement type #5829

Closed
scabug opened this issue May 24, 2012 · 6 comments

Comments

@scabug
Copy link

scabug commented May 24, 2012

trait Universe {
  type Tree

  type SymTree <: Tree
  type NameTree <: Tree
  type RefTree <: SymTree with NameTree

  type Ident <: RefTree
  type Select <: RefTree
}

object Test extends App {
  val universe: Universe = null
  import universe._
  def select: Select = ???
  def ident: Ident = ???
  List(select, ident)
}
C:\Projects\KeplerUnderRefactoring\sandbox @ topic/reflection>myke compile Test.scala
Test.scala:17: error: no type parameters for method apply: (xs: A*)List[A] in object List exist so that it can be applied to arguments (Test.universe.Select, Test.universe.Ident)
 --- because ---
undetermined type
  List(select, ident)
  ^
@scabug
Copy link
Author

scabug commented May 24, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5829?orig=1
Reporter: @xeno-by
Affected Versions: 2.10.0-M3, 2.10.0

@scabug
Copy link
Author

scabug commented May 24, 2012

@xeno-by said (edited on May 24, 2012 12:35:39 AM UTC):
As displayed in the debugger, tvar is a refinement type:

Test.universe.RefTree with Test.universe.SymTree with Test.universe.NameTree

Mapping over this type goes into:

case rtp @ RefinedType(parents, decls) =>
  val parents1 = parents mapConserve this
  val decls1 = mapOver(decls)
  //if ((parents1 eq parents) && (decls1 eq decls)) tp
  //else refinementOfClass(tp.typeSymbol, parents1, decls1)
  copyRefinedType(rtp, parents1, decls1)

parents for this refinement type are:

Test.universe.RefTree // TypeRef(pre = Test.universe.type, sym = type RefTree /* AbstractTypeSymbol */, args = Nil)
Test.universe.SymTree with Test.universe.NameTree // RefinementTypeRef (pre = NoType, sym = Universe /* RefinementClassSymbol */, args = Nil)

tvars map instantiate in Infer.scala calls instantiate:

object instantiate extends TypeMap {
  private var excludedVars = immutable.Set[TypeVar]()
  def apply(tp: Type): Type = tp match {
    case WildcardType | BoundedWildcardType(_) | NoType =>
      throw new NoInstance("undetermined type")
    case tv @ TypeVar(origin, constr) if !tv.untouchable =>
      if (constr.inst == NoType) {
        throw new DeferredNoInstance(() =>
          "no unique instantiation of type variable " + origin + " could be found")
      } else if (excludedVars(tv)) {
        throw new NoInstance("cyclic instantiation")
      } else {
        excludedVars += tv
        val res = apply(constr.inst)
        excludedVars -= tv
        res
      }
    case _ =>
      mapOver(tp)
  }
}

When navigating the second parent, instantiate sees NoType in pre and bails with NoInstance.

@scabug
Copy link
Author

scabug commented May 24, 2012

@xeno-by said (edited on May 24, 2012 6:28:03 AM UTC):
Also it's unclear why the lub is calculated as:

List(Test.universe.RefTree, Test.universe.SymTree with Test.universe.NameTree)

But not just to:

List(Test.universe.RefTree)

(the latter is how things work with concrete types)

@scabug
Copy link
Author

scabug commented May 24, 2012

@adriaanm said:
it looks like refinement typerefs lost their prefix in the Great Types Refactor of scala/scala@5f5029d2ac and scala/scala@f7535f7290 (specifically: scala/scala@f7535f7290#L2R2260)

This issue is an example of where the prefix is something interesting, and not just good old NoType (as assumed by scala/scala@f7535f7290#L2R1880). NoType indicates type inference failure. I could imagine it being NoPrefix once in a while, but never NoType.

fix in https://github.com/adriaanm/scala/tree/ticket/5829 pending it passing the test suite

@scabug
Copy link
Author

scabug commented Jun 9, 2012

@xeno-by said:
Fixed in scala/scala@6bb5975

@scabug scabug closed this as completed Jun 9, 2012
@scabug
Copy link
Author

scabug commented Apr 5, 2013

@paulp said:
Hey, I never saw this ticket.

For the record, and maybe you know this because you say "prefix is something interesting" which sounds like a reference to the comment, but I did this because it was documented by martin that "refinements always have non-interesting prefixes."

scala/scala@7ebc41cda2#L0R1453

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