| [#1006] | project: compiler | priority: low | category: bug | |
|---|---|---|---|---|
| submitter | assigned to | status | date submitted | |
| Nikolay | Martin | fixed | 2007-03-15 10:45:59.0 | |
| subject | [contrib #376] Generic type + subclass runs when compiled but not in interpreter | |||
| code |
Tested on: OSX 10.4 (JDK 1.5) and Windows XP (JDK 1.6)
Scala version: 2.3.3
I have two programs, almost identical. The first one is compiled with scalac and run with "scalac generic1.scala; scala RunMe".
----------------- generic1.scala ----------------------
abstract class A[T] {
def myVal: T
}
class B[T](value: T) extends A[T] {
def myVal = value
}
object RunMe extends Application {
Console.println(new B[int](23).myVal)
}
--------------------------------------------------------------
The second one is run in script mode, "scala generic2.scala"
----------------- generic2.scala ----------------------
abstract class A[T] {
def myVal: T
}
class B[T](value: T) extends A[T] {
def myVal = value
}
Console.println(new B[int](23).myVal)
--------------------------------------------------------------
|
|||
| what happened | generic1.scala compiles and runs, printing "23". generic2.scala gives an error message: generic2.scala:6: error: error overriding method myVal in class A of type => T; method myVal has incompatible type => T def myVal = value |
|||
| what expected | Both programs should run and produce the same output. | |||
| [back to overview] | ||||
| Nikolay edited on 2007-03-15 10:46:26.0 |
| contribution #376 |
| Lex edited on 2007-03-16 14:13:05.0 |
| This is something in the type checker. The programs behave differently due, in one case, to the A and B classes being embedded inside a method. Having classes inherit from each other inside a method looks odd to me, but I see no reason to disallow it. Anyway, I have comitted the modified version as test/pending/run/bug1006.scala. |
| Martin edited on 2007-03-19 15:19:25.0 |