Skip to content

Use of outer type argument in extension inline unapply(Seq) method causes compiler error #15188

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

Closed
gorilskij opened this issue May 14, 2022 · 5 comments · Fixed by #16358
Closed

Comments

@gorilskij
Copy link

Compiler version

#15053

Minimized code

object O

extension [T] (ctx: O.type) inline def unapplySeq(input: T): Option[Seq[T]] = Some(Seq(input)) 

@main
def Main = {
  val O(x) = 3
  println(s"x: $x")
}

Output

Compiler error

Exception in thread "main" java.lang.IndexOutOfBoundsException: 0
        at scala.collection.LinearSeqOps.apply(LinearSeq.scala:117)
        at scala.collection.LinearSeqOps.apply$(LinearSeq.scala:114)
        at scala.collection.immutable.List.apply(List.scala:79)
        at dotty.tools.dotc.core.Substituters$.substParams(Substituters.scala:151)
        at dotty.tools.dotc.core.Substituters$SubstParamsMap.apply(Substituters.scala:197)
        at dotty.tools.dotc.core.Substituters$SubstParamsMap.apply(Substituters.scala:197)
        at scala.collection.immutable.List.mapConserve(List.scala:472)
        at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:5553)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5582)
        at dotty.tools.dotc.core.Substituters$.substParams(Substituters.scala:161)
        at dotty.tools.dotc.core.Substituters$SubstParamsMap.apply(Substituters.scala:197)
        at dotty.tools.dotc.core.Types$TypeMap.mapOverLambda(Types.scala:5555)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5582)
        at dotty.tools.dotc.core.Substituters$.substParams(Substituters.scala:161)
        ...

Expectation

x: 3
@gorilskij gorilskij added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 14, 2022
@prolativ prolativ added area:pattern-matching itype:crash area:inline and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 16, 2022
@prolativ
Copy link
Contributor

The issue does not occur if unapplySeq is non-inline or if it's defined as an ordinary method rather than an extension

@prolativ
Copy link
Contributor

Compiler version: 3.2.0-RC1-bin-20220514-bb29e20-NIGHTLY

@szymon-rd szymon-rd assigned szymon-rd and unassigned szymon-rd May 19, 2022
@rmgk
Copy link

rmgk commented Jun 28, 2022

I ran into the same issue, you actually do not need any generics, and just unapply has the same issue.
Example:

class C

extension (ctx: C) inline def unapply(input: String): Option[String] = Some("hi")

@main def run = {
  val O = new C
  val O(x) = "3"
}

@gorilskij
Copy link
Author

@rmgk
That's a different side of the same issue, see #8577
Both should eventually be resolved by #15191

@nicolasstucki nicolasstucki self-assigned this Nov 17, 2022
@nicolasstucki
Copy link
Contributor

We should check if #16358 fixes this

nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Nov 17, 2022
Fixes the computation of the inline unapply temporary unanimous unapply placeholder.

Fixes scala#8577
Fixes scala#15188
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Nov 18, 2022
Fixes the computation of the inline unapply temporary unanimous unapply placeholder.

Fixes scala#8577
Fixes scala#15188
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Dec 7, 2022
* Fixes the computation of the inline unapply temporary unanimous unapply placeholder
* Handle leading given parameters in inline unapplies

Fixes scala#8577
Fixes scala#12991
Fixes scala#15188
nicolasstucki added a commit that referenced this issue Dec 7, 2022
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
* Fixes the computation of the inline unapply temporary unanimous unapply placeholder
* Handle leading given parameters in inline unapplies

Fixes scala#8577
Fixes scala#12991
Fixes scala#15188
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants