scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Strange Errors When Overloading ==() #1239

Closed scabug closed 13 years ago

scabug commented 16 years ago

Very strange things happen when I define a method: ==(...). Example definition:

class Test {
  def ==(other: Test) = 123    // not Boolean
}

The trick seems to be when defining == not to return of type Boolean. I'm afraid I don't have a minimal test case, but the end result is errors at seemingly-arbitrary (but consistent) points in the code. These points in code are never anywhere near a use of the == method or even any instance of the class which defines it. It seems that what happens is the parser makes certain assumptions about the == method and possibly inlines a few expressions or definitions. This is eventually passed on to the type checker, which recognizes that == does not return Boolean for that type. I'm assuming that odd error locations are due to whatever the parser is doing.

Sample error:

C:\Users\Daniel Spiewak\Development\workspace\scala_ql\src\main\scala\edu\uwm\cs\sql\tree\nodes.scala:24: error: type mismatch;
 found   : edu.uwm.cs.sql.tree.And
 required: Boolean
case class LessThanNum(left: NumericExpression, right: NumericExpression) extends BooleanExpression with BinaryTemplateResolution {
           ^

The == method is defined in a superclass of {Numeric, Binary}Expression and is defined to return a value of type BooleanExpression.

scabug commented 16 years ago

Imported From: https://issues.scala-lang.org/browse/SI-1239?orig=1 Reporter: @djspiewak

scabug commented 16 years ago

@dragos said: Please add or attach a complete program exhibiting these errors. It would greatly increase the chances for a quick fix...

scabug commented 16 years ago

@TiarkRompf said: I'm afraid we can't do much without having a test case to reproduce the errors. So I'm closing this one for now.