Type inference bug in Scala 3.1.2
See original GitHub issueI’m unsure if I’m reporting this issue in the right place.
Compiler version
3.1.2
— the issue does not happen in 3.0.x
or in 3.1.1
.
First bad commit db5956b36a7e62b77f4b3a9335ab1587e0e47e2c in #13886
Minimized code
Noticed it while upgrading to 3.1.2 in monix/newtypes:
trait Eq[A] {
def eqv(a1: A, a2: A): Boolean
}
given stringEq: Eq[String] with {
def eqv(a1: String, a2: String) = a1 == a2
}
abstract class Newtype[Src] {
opaque type Type = Src
protected final def derive[F[_]](using ev: F[Src]): F[Type] = ev
}
object Sample extends Newtype[String] {
given eq: Eq[Type] = derive
}
Output
[error] -- Error: .../Sample.scala:16:29
[error] 16 | given eq: Eq[Type] = derive
[error] | ^
[error] |no implicit argument of type F[String] was found for parameter ev of method derive in class Newtype
[error] |
[error] |where: F is a type variable with constraint <: Eq
[error] one error found
Expectation
The code should compile just fine, as it does with 3.1.1
, 3.0.2
, or 2.13.x
.
Issue Analytics
- State:
- Created a year ago
- Comments:11 (9 by maintainers)
Top Results From Across the Web
A Classification of Proposed Language Features - Scala 3
The Scala 3 compiler uses a new algorithm for type inference, which relies on a general subtype constraint solver. The new algorithm often...
Read more >Type Inference | Tour of Scala
The Scala compiler can often infer the type of an expression so you don't have to declare it explicitly. Omitting the type.
Read more >Migration Guide: SQL, Datasets and DataFrame - Spark 3.1.2 ...
Set the JSON option inferTimestamp to true to enable such type inference. Upgrading from Spark SQL 2.4 to 3.0. Dataset/DataFrame APIs. In Spark...
Read more >A Study of Typing-Related Bugs in JVM Compilers
type inference or a mix of object-oriented with functional programming ... checker of the Scala 2 compiler (typer) is the component that suffers...
Read more >Databricks Runtime 9.1 LTS - Azure - Microsoft Learn
Array and map types are supported in Override schema inference with schema hints for Auto Loader. Examples of schema hints for arrays include:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
👋 from my perspective as a user, if you say there are technical challenges that make this impractical, I believe you. It was surprising to me, as it used to work, and now it doesn’t.
If this helps compile times, then that may be a useful trade-off.
But maybe you can improve the error message a little? I’m beginning to be spoiled by Scala 3’s cool error message. IDK 🤷♂️
Not sure I understand. Type variables bound in polytypes are usually meant to be instantiated by the implicit search, no?