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

Scalac crash on erroneous code #5687

Closed
scabug opened this Issue Apr 20, 2012 · 7 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

scabug commented Apr 20, 2012

[minimized from the original report]

abstract class Template[T <: AnyRef](private val t: T) {

  type Repr[T]<:Template[T]

  def withTimeout(timeout:Long): Repr[T] = this.asInstanceOf[Repr[T]]
  def withReadModifiers(readModifiers:Int): Repr[T] = this.asInstanceOf[Repr[T]]
}

class Curve

class CurveTemplate [T <: Curve](t: T) extends Template(t) {
  type Repr = CurveTemplate[T]
}


object Example {
 new CurveTemplate(new Curve).withTimeout(2000L).withReadModifiers(0)
}
@scabug

This comment has been minimized.

Copy link

scabug commented Apr 20, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5687?orig=1
Reporter: Edmondo Porcu (edmondo1984)
Affected Versions: 2.9.1, 2.10.0
Attachments:

@scabug

This comment has been minimized.

Copy link

scabug commented Apr 20, 2012

Edmondo Porcu (edmondo1984) said:
Curiously, the problem seems to be introduced by the cast to the abstract type.

If the abstract type is replaced by an extra generic parameter, everything works fine and compile

@scabug

This comment has been minimized.

Copy link

scabug commented Apr 20, 2012

@som-snytt said:
The useful error messages can be elicited by speaking very slowly to scalac (or by commenting the expression entirely):

    /*
porcu.scala:5: error: type arguments [T] do not conform to class Template's type parameter bounds [T <: Object]
  type Repr[T]<:Template[T]
                ^
porcu.scala:42: error: overriding type Repr in class Template with bounds[T] <: gist2427426.Template[T];
 type Repr has incompatible type
  type Repr = CurveTemplate[T]
       ^
two errors found
    */

// in the attached code
object Example {
  def main(args:Array[String]) ={
    /*
    val template = new CurveTemplate(new Curve).withTimeout(2000L).withReadModifiers(ReadModifiers.DIRTY_READ).resolve
    println(template)
    */
    /*
    val a = new CurveTemplate(new Curve)
    val b = a.withTimeout(2000L)
// This is not yet germane
    //error: value withReadModifiers is not a member of a.Repr[gist2427426.Curve]
    val c = b.withReadModifiers(ReadModifiers.DIRTY_READ)
    val d = c.resolve
    println(d)
    */
    val a: CurveTemplate[Curve] = new CurveTemplate(new Curve)
    val b: CurveTemplate[Curve] = a.withTimeout(2000L)
    val c: CurveTemplate[Curve] = b.withReadModifiers(ReadModifiers.DIRTY_READ)
    val d = c.resolve
    println(d)
  }
}
@scabug

This comment has been minimized.

Copy link

scabug commented Apr 21, 2012

Edmondo Porcu (edmondo1984) said:
I am bit able to get the compiler error with 2.9.1 because the compiler crashes. What did you do to get the error message?

@scabug

This comment has been minimized.

Copy link

scabug commented Jun 28, 2012

@hubertp said:
Note that you will get the correct error message if you comment out everything apart from Template class.
This is because checking the bounds is done during refchecks.

new CurveTemplate(new Curve).withTimeout(2000L)

will need to perform dealiasing in order to get the type of withTimeout (again before Refchecks) and that will simply have ErrorType as a result type, which already gives you pretty uninformative error message.
Now, if you additionally call on the result

... .withReadModifiers(...)

it is just getting lost and crashes after typers. So either we will be checking the bounds earlier or basically we defer this check until refchecks.
I have a solution for that, but it needs a bit more testing.

@scabug

This comment has been minimized.

Copy link

scabug commented Jul 10, 2012

@hubertp said:
Bumping to critical, I want to fix this for 2.10. #811 contains a fix but it needs a bit more work.

@scabug scabug closed this Aug 8, 2012

@scabug

This comment has been minimized.

Copy link

scabug commented Aug 8, 2012

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