question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type inference bug in Scala 3.1.2

See original GitHub issue

I’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:closed
  • Created a year ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
alexandrucommented, May 18, 2022

👋 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 🤷‍♂️

0reactions
oderskycommented, May 19, 2022

It looks like the implementation only looks for type variables in MethodTypes right now, but it seems like it could look in PolyTypes too.

Not sure I understand. Type variables bound in polytypes are usually meant to be instantiated by the implicit search, no?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found