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
Overloading in package object #1987
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1987?orig=1
|
@okomok said: |
@dubochet said: |
@paulp said: |
Erkki Lindpere (villane) said: File1: } File2: class Client { |
Erkki Lindpere (villane) said: File1.scala package bug
package object packageb {
def func(a: Int) = ()
def func(a: String) = ()
} File2.scala package bug.packageb
class Client {
val x = func(1) // doesn't compile: type mismatch; found: Int(1) required: String
val y = func("1") // compiles
} |
Harrison Klaperman (hlklaperman) said: package object test {
def foo(a: Int, b: Int) = a + b
def foo(a: Int, b: Int, c: Int) = a + b + c
def bar[A, B](a: A, b: B) = (a, b)
def bar[A, B, C](a: A, b: B, c: C) = (a, b, c)
def baz(a: AnyVal) = a
def baz(a: String) = a
def baz(a: Seq[_]) = a
def test1() {
foo(1, 2)
foo(1, 2, 3)
bar(1, 2)
bar(1, 2, 3)
bar('a', new Object)
bar('a', new Object, 'a'.asInstanceOf[AnyRef])
baz(5)
baz("5")
}
} The above file compiles with no errors. In another file we have the exact same method package test
object Test {
def test1() {
foo(1, 2)
foo(1, 2, 3)
bar(1, 2)
bar(1, 2, 3)
bar('a', new Object)
bar('a', new Object, 'a'.asInstanceOf[AnyRef])
baz(5)
baz("5")
}
} The compiler reports the following errors: test2.scala:5: error: not enough arguments for method foo: (a: Int,b: Int,c: Int)Int.
Unspecified value parameter c.
foo(1, 2)
^
test2.scala:8: error: not enough arguments for method bar: (a: A,b: B,c: C)(A, B, C).
Unspecified value parameter c.
bar(1, 2)
^
test2.scala:10: error: not enough arguments for method bar: (a: A,b: B,c: C)(A, B, C).
Unspecified value parameter c.
bar('a', new Object)
^
test2.scala:13: error: type mismatch;
found : Int(5)
required: Seq[_]
baz(5)
^
four errors found I think this is a pretty big bug in package objects. |
Harrison Klaperman (hlklaperman) said: |
@paulp said: ./a.scala:30: error: reference to foo is ambiguous;
it is both defined in object test and imported subsequently by
import test._
foo(1, 2)
^
./a.scala:31: error: reference to foo is ambiguous;
it is both defined in object test and imported subsequently by
import test._
foo(1, 2, 3)
^ etc. |
@retronym said: |
Harrison Klaperman (hlklaperman) said: |
@non said (edited on Jan 13, 2012 6:21:47 AM UTC): // package.scala
package foo
package object bar {
def duh(n:Long) = println("long")
def duh(n:Double) = println("double")
} // main.scala
package foo.bar
object Main {
def main(args:Array[String]) {
duh(33L)
foo.bar.duh(33L)
}
} Output:
In the wild it takes a moment to notice that this is going on because the Long values will get coerced into Doubles. Currently scala.math would hit this bug in a big way if it needed to use its own functions (e.g. abs). I noticed this when writing a similar "math package". |
@paulp said: |
@paulp said: |
@non said: |
Chris (chris) said (edited on Aug 22, 2012 9:54:29 PM UTC): The code will "compile" but it generates CCEing byte code: scaley.funny.package$ cannot be cast to scales.xml.PullIteratees which is true, but for some reason the compiler generates it. The code is here: https://github.com/chris-twiner/scalesXml/tree/cdeb3a7e04d15cf77c9fda4d406c3eb403920a18 4 very small files plus the build.sbt. clean + run and you'll see the cce. I've commented in the code what can stop the cce, any of which forces
|
@paulp said: |
Chris (chris) said: |
@adriaanm said: |
Trivial overloading resolution in package object doesn't work?
The text was updated successfully, but these errors were encountered: