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

Regression in 7mind/izumi for implicit search / typer #19942

Closed
WojciechMazur opened this issue Mar 13, 2024 · 1 comment · Fixed by #19974
Closed

Regression in 7mind/izumi for implicit search / typer #19942

WojciechMazur opened this issue Mar 13, 2024 · 1 comment · Fixed by #19974
Assignees
Labels
area:implicits related to implicits area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Based on Open CB failure found in 7mind/izumi - build logs
When the Identity type is placed in different scope then rest of the code, implicit cannot be found.

Compiler version

Last good release: 3.4.2-RC1-bin-20240222-98efdab-NIGHTLY
First bad release: 3.4.2-RC1-bin-20240226-e0cb1e7-NIGHTLY
Bisect points to 729e5ba

Minimized code

type LifecycleF = [_] =>> Any
trait Lifecycle[+F[_], +A]

trait LifecycleTag[R]
object LifecycleTag:
  implicit def resourceTag[R <: Lifecycle[F0, A0], F0[_], A0]: LifecycleTag[R] = ???

trait MakeDSL[T]:
  final def fromResource[R <: Lifecycle[LifecycleF, T]](implicit tag: LifecycleTag[R]): Any = ???

object distage:
  // Cannot be defined in the same scope as rest of code
  final type Identity[+A] = A
import distage.*

trait Resource
trait DependentResource() extends Lifecycle[Identity, Resource]

@main def Test =  {
  val dsl: MakeDSL[Resource] = ???
  val fails = dsl.fromResource[DependentResource]
  val works = dsl.fromResource[DependentResource](using LifecycleTag.resourceTag[DependentResource, Identity, Resource])
}

Output

Compiling project (Scala 3.4.2-RC1-bin-20240312-3694d95-NIGHTLY, JVM (17))
[error] ./test.scala:50:50
[error] No given instance of type LifecycleTag[DependentResource] was found for parameter tag of method fromResource in trait MakeDSL.
[error] I found:
[error] 
[error]     LifecycleTag.resourceTag[R, F0, A0]
[error] 
[error] But method resourceTag in object LifecycleTag does not match type LifecycleTag[DependentResource].
[error]   val fails = dsl.fromResource[DependentResource]
[error]                                                  ^
Error compiling project (Scala 3.4.2-RC1-bin-20240312-3694d95-NIGHTLY, JVM (17))

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer area:implicits related to implicits regression This worked in a previous version but doesn't anymore labels Mar 13, 2024
@WojciechMazur
Copy link
Contributor Author

WojciechMazur commented Mar 15, 2024

The bisect points to the same commit also in typelevel/kittens(build logs) when companion object defining type alias is defined AFTER class/trait refers to type alias in implicit search

Minimization

trait Alternative[F[_]]

opaque type Derived[A] = A
object Derived:
  extension [A](derived: Derived[A]) def instance: A = derived
  infix type <<<[F[_], G[_]] = [x] =>> F[G[x]]

import Derived.*
import scala.compiletime.summonInline

type DerivedAlternative[F[_]] = Derived[Alternative[F]]
object DerivedAlternative:
  inline def apply[F[_]]: Alternative[F] =
    import DerivedAlternative.given
    summonInline[DerivedAlternative[F]].instance
  given nested[F[_], G[_]]: DerivedAlternative[F <<< G] = ???

object auto:
  object alternative:
    transparent inline given [F[_]]: Alternative[F] = DerivedAlternative[F]

trait Test:
  import Test.*
  import auto.alternative.given
  val fails = summon[Alternative[OptList]]

// Fails if companion object defined AFTER trait
object Test:
  type OptList[A] = Option[List[A]]

Output:

-- [E172] Type Error: /Users/wmazur/projects/scala3/bisect/main.scala:25:42 ----
25 |  val fails = summon[Alternative[OptList]]
   |                                          ^
   |No given instance of type main$package$_this.DerivedAlternative[[A] =>> Test.OptList[A]] was found.
   |I found:
   |
   |    auto.alternative.given_Alternative_F[[A] =>> Test.OptList[A]]
   |
   |But given instance given_Alternative_F in object alternative does not match type main$package$_this.DerivedAlternative[[A] =>> Test.OptList[A]].
   |----------------------------------------------------------------------------
   |Inline stack trace
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from main.scala:15
15 |    summonInline[DerivedAlternative[F]].instance
   |    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   |This location contains code that was inlined from main.scala:15
20 |    transparent inline given [F[_]]: Alternative[F] = DerivedAlternative[F]
   |                                                      ^^^^^^^^^^^^^^^^^^^^^
    ----------------------------------------------------------------------------
1 error found

@dwijnand dwijnand self-assigned this Mar 16, 2024
odersky added a commit that referenced this issue Mar 18, 2024
…completions (#19974)

Fixes #19942 

Based on #19960 

@dwijnand I would have pushed onto the original PR if it had been on
staging. Better to always push to staging, not your own repo.
@Kordyjan Kordyjan added this to the 3.4.2 milestone Mar 28, 2024
@Kordyjan Kordyjan modified the milestones: 3.4.2, 3.5.0 May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
3 participants