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

MatchError in Quotes.TreeMap for local class definition with type parameter #19480

Closed
ghik opened this issue Jan 18, 2024 · 0 comments · Fixed by #19485
Closed

MatchError in Quotes.TreeMap for local class definition with type parameter #19480

ghik opened this issue Jan 18, 2024 · 0 comments · Fixed by #19485
Assignees
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug
Milestone

Comments

@ghik
Copy link

ghik commented Jan 18, 2024

Compiler version

3.3.1

Minimized code

import scala.quoted.*

object BadMacros {
  inline def whatever: Int = ${whateverImpl}

  def whateverImpl(using Quotes): Expr[Int] = {
    import quotes.reflect.*
    val t = '{class K[T]}.asTerm
    object mapper extends TreeMap
    mapper.transformTree(t)(Symbol.spliceOwner)
    '{42}
  }
}

Output

Upon invocation of whatever, this happens:

Exception occurred while executing macro expansion.
scala.MatchError: TypeBoundsTree(Inferred(), Inferred()) (of class java.lang.String)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTypeTree(Quotes.scala:4991)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTypeTree$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformTypeTree(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree(Quotes.scala:4858)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformTree(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement(Quotes.scala:4897)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformStatement(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.$anonfun$5(Quotes.scala:4905)
	at scala.collection.immutable.List.map(List.scala:246)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement(Quotes.scala:4905)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformStatement(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStats$$anonfun$1(Quotes.scala:5003)
	at scala.collection.immutable.List.mapConserve(List.scala:472)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStats(Quotes.scala:5003)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStats$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformStats(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4941)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformTerm(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm(Quotes.scala:4957)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTerm$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformTerm(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement(Quotes.scala:4882)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformStatement$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformStatement(BadMacros.scala:11)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree(Quotes.scala:4857)
	at scala.quoted.Quotes$reflectModule$TreeMap.transformTree$(Quotes.scala:4846)
	at utest.BadMacros$mapper$2$.transformTree(BadMacros.scala:11)
	at utest.BadMacros$.whateverImpl(BadMacros.scala:12)

Expectation

No error

@ghik ghik added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 18, 2024
@nicolasstucki nicolasstucki added area:metaprogramming:reflection Issues related to the quotes reflection API and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 19, 2024
@nicolasstucki nicolasstucki self-assigned this Jan 19, 2024
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 19, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  scala#19480
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 19, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  scala#19480
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 19, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  scala#19480
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 4, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  scala#19480
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Mar 6, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  scala#19480
nicolasstucki added a commit that referenced this issue Mar 11, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  #19480
@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 2, 2024
Also see `TypeBoundsTreeTypeTest` in `QuotesImpl` and `Quotes` spec

```
   *           +- TypeTree ----+- Inferred
   *           |               +- ...
   *           |               ...
   *           +- TypeBoundsTree
```

Fixes  #19480

[Cherry-picked 00f11a3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:reflection Issues related to the quotes reflection API itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants