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

Wrong type inferred for variables with this.type #5210

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

Comments

Projects
None yet
1 participant
@scabug
Copy link

scabug commented Nov 21, 2011

The following works in 2.9.1 (and earlier versions) but fails in trunk (2011-11-21):

object WithOpTest {

trait WithOp extends Cloneable {

  def f: this.type = this

  def g1: this.type = {
    f
  }

  def g2: this.type = {
    val t = f
    t
  }

}

}

Using f directly in g1 is OK but assigning it to an intermediate variable in g2 fails:

C:\Users\szeiger\Desktop>scalac Test.scala

C:\Users\szeiger\Desktop>c:\StandaloneApps\scala-2.10.0.r26037-b20111121023229\bin\scalac Test.scala
Test.scala:13: error: type mismatch;
 found   : t.type (with underlying type WithOpTest.WithOp)
 required: WithOp.this.type
    t
    ^
one error found

Adding an explicit type annotation ": this.type" to t also makes it work.

@scabug

This comment has been minimized.

Copy link

scabug commented Nov 21, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5210?orig=1
Reporter: @szeiger
Affected Versions: 2.10.0

@scabug

This comment has been minimized.

Copy link

scabug commented Nov 23, 2011

@paulp said:
Regression in r25879, caused by me.

I'm kind of surprised it ever worked (especially as there are no tests defending it.)

@scabug

This comment has been minimized.

Copy link

scabug commented May 13, 2012

@paulp said:
Fixed in 09f380dbda .

@scabug

This comment has been minimized.

Copy link

scabug commented Dec 5, 2012

@odersky said:
I believe the original behavior was buggy. The test case should not compile.

@scabug

This comment has been minimized.

Copy link

scabug commented Jul 22, 2016

@milessabin said:
This was (and still is) fixed in 09f380dbda and has a test corresponding to the example above so could be resolved as closed, fixed.

@scabug scabug closed this Aug 2, 2016

@scabug scabug added the critical label Apr 7, 2017

@scabug scabug added this to the 2.10.0-RC1 milestone Apr 7, 2017

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