Skip to content
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

Compilation error with @specialized #10072

Closed
scabug opened this issue Nov 18, 2016 · 6 comments
Closed

Compilation error with @specialized #10072

scabug opened this issue Nov 18, 2016 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Nov 18, 2016

The following snippet compiles under 2.11.8 but does not compile under 2.12:

trait Foo[@specialized(Double,AnyRef)T] extends IndexedSeq[T] {

  override def sum[@specialized(Double, AnyRef) B >: T](implicit num: Numeric[B]): B = {
    foldLeft(num.zero)(num.plus)
  }
}

Compilation error:

[error] Foo.scala:4: type mismatch;
[error]  found   : (Double, Double) => Double
[error]  required: (Double, T) => Double
[error]     foldLeft(num.zero)(num.plus)
[error]                            ^
@scabug
Copy link
Author

scabug commented Nov 18, 2016

Imported From: https://issues.scala-lang.org/browse/SI-10072?orig=1
Reporter: Kamil Kloch (kamilk)
Affected Versions: 2.12.0

@scabug
Copy link
Author

scabug commented Dec 5, 2016

@lrytz said:
For me, the snippet doesn't compile in 2.11.8. I actually get two errors in 2.11.8:

Test.scala:3: error: type mismatch;
 found   : (Double, <empty>.T) => Double
 required: (Double, T(in trait Foo)) => Double
    foldLeft(num.zero)(num.plus)
                           ^
Test.scala:3: error: type mismatch;
 found   : B(in method sum$mcD$sp)
 required: <empty>.B
    foldLeft(num.zero)(num.plus)
                      ^

@scabug
Copy link
Author

scabug commented Dec 5, 2016

Kamil Kloch (kamilk) said:
@lukasz Rytz: it does compile on 2.11.8
https://github.com/kamilkloch/SI-10072

@scabug
Copy link
Author

scabug commented Dec 5, 2016

@lrytz said:
now it works for me too - i have no idea what i did wrong before..

@scabug
Copy link
Author

scabug commented Dec 6, 2016

@lrytz said (edited on Dec 6, 2016 8:06:51 PM UTC):
Intermediate result: this is related to #5284, which was fixed in scala/scala#755, i still have to spend some time to understand that change.

The example in this ticket compiles using -Ydelambdafy:inline, in which case the castType method introduced in the above PR casts the function instantiation (new anonfun) to the necessary type (Int, A) => Int.

This cast is not performed under -Ydelambdafy:method, where the Function survives until specialization and is not replaced by new anonfun. So "duplicators" attempts to re-typecheck (x: B, y: B) => $anonfun$sum(x, y) with expected type (Int, A) => Int, which then yields the type mismatch.

@scabug
Copy link
Author

scabug commented Dec 7, 2016

@lrytz said:
scala/scala#5587

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

No branches or pull requests

2 participants