Skip to content

Regression in tinkoff/oolong, missing type parameter in quotes #18228

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
WojciechMazur opened this issue Jul 17, 2023 · 1 comment · Fixed by #18240
Closed

Regression in tinkoff/oolong, missing type parameter in quotes #18228

WojciechMazur opened this issue Jul 17, 2023 · 1 comment · Fixed by #18240
Assignees
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Compiler version

Works in 3.3.1-RC4
Fails in 3.3.2-RC nightly

Bisect points to 3c07379

Minimized code

import scala.quoted.*

case class QueryMeta[T](map: Map[String, String])

object QueryMeta:
  given [T]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:
    def unapply(expr: Expr[QueryMeta[T]])(using q: Quotes): Option[QueryMeta[T]] =
      import q.reflect.*
      expr match
        case '{ QueryMeta(${ map }: Map[String, String]) } =>
          map.value.map(QueryMeta[T].apply)
        case _ =>
          None

Output

-- Error: /Users/wmazur/projects/dotty/bisect/main.scala:10:16 -----------------
10 |        case '{ QueryMeta(${ map }: Map[String, String]) } =>
   |                ^^^^^^^^^
   |Reference to T within quotes requires a given scala.quoted.Type[T] in scope.
   |
1 error found

Workaround

        case '{ QueryMeta[t](${ map }: Map[String, String]) } =>

Expectation

It makes sense that quotes it fails when type parameter is failing, but the error message seems to not be very pricise here. It would make sense to make this code compile in 3.3.x for LTS source compatibility, and change semantics in 3.4.x

@WojciechMazur WojciechMazur added itype:bug regression This worked in a previous version but doesn't anymore area:metaprogramming:quotes Issues related to quotes and splices labels Jul 17, 2023
@nicolasstucki
Copy link
Contributor

In 3c07379 we unintentionally fixed type inference for this pattern. Previously we wrongly inferred '{ QueryMeta[Any](...) } and now we infer '{ QueryMeta[T](...) }. Because we use this T in the quote pattern, we do need a given Type[T].

The correct fix for this code is

-  given [T]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:
+  given [T: Type]: FromExpr[QueryMeta[T]] = new FromExpr[QueryMeta[T]]:

Though the workaround is also fine

case '{ QueryMeta[t](${ map }: Map[String, String]) } =>

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jul 18, 2023
WojciechMazur added a commit to WojciechMazur/oolong that referenced this issue Jul 18, 2023
danslapman pushed a commit to Tinkoff/oolong that referenced this issue Jul 18, 2023
nicolasstucki added a commit that referenced this issue Jul 19, 2023
Kordyjan pushed a commit that referenced this issue Dec 1, 2023
Closes #18228

[Cherry-picked 96c511e]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metaprogramming:quotes Issues related to quotes and splices 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.

2 participants