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 tarao/record4s - transparent inline looses type dependent type info in match #19623

Closed
WojciechMazur opened this issue Feb 6, 2024 · 0 comments · Fixed by #19646
Assignees
Labels
area:inline area:typer itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@WojciechMazur
Copy link
Contributor

Regression found in OpenCB for tarao/record4s - build logs
All transparent inline given instances used in match block are loosing information about dependent type, it does not happen when calling unapply outside match block.

Compiler version

Last good release: 3.4.1-RC1-bin-20240129-b20747d-NIGHTLY
First bad release: 3.4.1-RC1-bin-20240130-7a5cb6e-NIGHTLY
Bisect points to 5648f12

Minimized code

import scala.compiletime.*
import scala.language.dynamics

abstract class % extends Selectable

trait Select { type Out <: % }
trait Selector extends Dynamic {
  def selectDynamic[S <: Singleton & String](label: S): Any = ???
  
  def unapply[R: RecordLike](record: R)(using
      t: Select,
      r: RecordLike[t.Out]
  ): r.ElemTypes = ???
}

trait RecordLike[R] {
  type ElemTypes <: Tuple
}


@main def Test = {
  val r: %{ val name: String; } = ???

  // originally derived in macro, use dummy instance instead
  transparent inline given outputRecordLike[R <: %]: RecordLike[R] = null.asInstanceOf[
    RecordLike[R] {
      type ElemTypes = String *: EmptyTuple
    }
  ]

  type FieldSelector = Select { type Out = % { val name: String } }
  given fieldSelector: FieldSelector = ???
  val selector: Selector = ???

  val works = selector.unapply(r)
  val works2 = selector.unapply(r)(using summon, fieldSelector, summon) 
  r match {
    case selector(value) => value // compilation error
  }
}

Output

- [E108] Declaration Error: /Users/wmazur/projects/dotty/bisect/main.scala:38:17 
38 |    case selector(value) => value // compilation error
   |         ^^^^^^^^^^^^^^^
   | ?1.ElemTypes is not a valid result type of an unapply method of an extractor.
   |
   |where:    ?1 is an unknown value of type RecordLike[%{val name: String}]
   |
   | longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: /Users/wmazur/projects/dotty/bisect/main.scala:38:28 
38 |    case selector(value) => value // compilation error
   |                            ^^^^^
   |                            Not found: value - did you mean valueOf?
   |
   | longer explanation available when compiling with `-explain`
2 errors found

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:typer area:inline regression This worked in a previous version but doesn't anymore labels Feb 6, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 8, 2024
We needed to delay the inlining of the transparent inline when typing
the unapply function application. We used the NoInline mode, but this
also stopped the inlining of the arguments of the unapply. To fix this
we introduce a new mode, NoInlineUnapply, which is used to delay only
the inlining of the unapply method and not the implicit arguments.

Fixes scala#19623
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 8, 2024
We needed to delay the inlining of the transparent inline when typing
the unapply function application. We used the NoInline mode, but this
also stopped the inlining of the arguments of the unapply. To fix this
we introduce a new mode, NoInlineUnapply, which is used to delay only
the inlining of the unapply method and not the implicit arguments.

Fixes scala#19623
odersky added a commit that referenced this issue Feb 27, 2024
)

We needed to delay the inlining of the transparent inline when typing
the unapply function application. We used the NoInline mode, but this
also stopped the inlining of the arguments of the unapply. To fix this
we target more precisely the inlining of the unapply method and not the
implicit arguments. To do this we detect the dummy argument that is used
type the unapply as an application, before it is transformed into a
pattern.

Fixes #19623
Fixes solution added in #19380
@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
WojciechMazur pushed a commit that referenced this issue Jul 5, 2024
We needed to delay the inlining of the transparent inline when typing
the unapply function application. We used the NoInline mode, but this
also stopped the inlining of the arguments of the unapply. To fix this
we target more precisely the inlining of the unapply method and not the
implicit arguments. To do this we detect the dummy argument that is used
type the unapply as an application, before it is transformed into a pattern.

Fixes #19623

[Cherry-picked d244a30]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:inline area:typer itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants