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

Bogus type mismatch reported against default implicit argument #5259

Closed
scabug opened this Issue Nov 30, 2011 · 5 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Nov 30, 2011

With trunk as of 2.10.0.r26093-b20111130020250 compiling the following,

class A[T]
class B {
  def m(a: A[this.type] = new A[this.type]) { }
}

object DefaultArgBogusTypeMismatch {
  def newB = new B

  newB.m()

  // this compiles
  // val stableB = new B
  // stableB.m()
}

Results in the error report below,

t5259.scala:9: error: type mismatch;
 found   : A[_2.type] where val _2: B
 required: A[_1.type] where val _1: B
  newB.m()
       ^

Adriaan's comment is that it shouldn't be necessary to existentially abstract over the "this" reference, which is what's causing the problem here.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented Nov 30, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5259?orig=1
Reporter: @milessabin
Affected Versions: 2.9.1, 2.10.0

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 14, 2012

@lrytz said:
same behavior since at least 2.8.1

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 15, 2012

@lrytz said:
This is not so easy to fix. The invocation

newB.m()

is first transformed by named/default args to

{ val qual$1 = newB
  qual$1.m(qual$1.m$default$1)
}

In the method call qual$1.m, the qualifier tree Ident(qual$1) is created in blockWithQualifier using gen.mkAttributedRef which doesn't assign a SingleType.

That's why the qualifier has type B instead of SingleType(qual$1). Selecting the m method therefore has an existential type
qual$1.m: (a: A[_1.type])Unit

Note that I applied a small change which runs the type-checker on the Select node, instead of assigning the type directly:

-          val f = Select(gen.mkAttributedRef(sym), selected)
-                   .setType(baseFun1.tpe).setSymbol(baseFun1.symbol)
+          val sel = Select(gen.mkAttributedRef(sym), selected)
+          val f = blockTyper.typedOperator(sel)

Then there's the question why qual$1.m$default$1 also has an existential types, but I guess it's something along the same lines.

Anyway, I'll stop working on this for now, it seems a very cornery case, and there's no deep underlying bad bug, it's due to the singleton this.type.

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 15, 2012

@lrytz said:
Oh, I just realized that we can create an Ident tree and type-check it instead of using gen.mkAttributedRef, that should be fine in this case (it's always an Ident to a the local value). So now the question is only about qual$1.m$default$1

@scabug scabug closed this May 16, 2012

@scabug

This comment has been minimized.

Copy link
Author

scabug commented May 16, 2012

@lrytz said:
fixed in scala/scala#558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment