scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Explicit import to `scala.Predef.assert` can infer typer results for valid code

Open WojciechMazur opened this issue 1 week ago • 6 comments

There seems to be something strange happening if scala.Predef.assert is explicitlly imported. Issue spotted by OpenCB in iltotore/iron. Was spotted after applying patch to replace no longer allowed import scala.runtime.stdlibPatches.assert with scala.Predef.assert (required to shadow assert from utest library)

If we'd remove import scala.Predef.assert or use import io.github.iltotore.iron.{*, given} instead of package io.github.iltotore.iron the code would compile (the test code of mentioned library) Otherwise we get a compile error hinting that implicit conversion was not applied

Issue requires further minimization, I'll try to provide it in the upcoming days

Compiler version

All Scala versions: tested with 3.3.7 and 3.8.0-RC2

Reproducer code

//> using dep "io.github.iltotore::iron-cats:3.2.1"

// import io.github.iltotore.iron.{*, given} // works 
package io.github.iltotore.iron // fails

import _root_.cats.kernel.CommutativeSemigroup
import _root_.cats.instances.all.*
import io.github.iltotore.iron.cats.{*, given}
import io.github.iltotore.iron.constraint.all.*

import scala.Predef.assert // comment it to make it compile

@main def Test = 
    assert(CommutativeSemigroup[Int :| Positive].combine(1, 5) == 6)

Output

error] ./test.scala:14:58
[error] Found:    (1 : Int)
[error] Required: io.github.iltotore.iron.IronType[Int,
[error]   io.github.iltotore.iron.constraint.all.Positive]
[error] 
[error] The following import might fix the problem:
[error] 
[error]   import io.github.iltotore.iron.autoRefine
[error] 
[error]     assert(CommutativeSemigroup[Int :| Positive].combine(1, 5) == 6)
[error]                                                          ^
[error] ./test.scala:14:61
[error] Found:    (5 : Int)
[error] Required: io.github.iltotore.iron.IronType[Int,
[error]   io.github.iltotore.iron.constraint.all.Positive]
[error] 
[error] The following import might fix the problem:
[error] 
[error]   import io.github.iltotore.iron.autoRefine
[error] 
[error]     assert(CommutativeSemigroup[Int :| Positive].combine(1, 5) == 6)
[error]                                                             ^
Error compiling project (Scala 3.3.7, JVM (21))

Expectation

Should compile in every combination

WojciechMazur avatar Dec 02 '25 07:12 WojciechMazur