Skip to content

Regression macro matching with Varargs fails: Sequence argument type annotation * cannot be used here #19709

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
hmf opened this issue Feb 16, 2024 · 4 comments
Labels
area:metaprogramming:quotes Issues related to quotes and splices itype:invalid

Comments

@hmf
Copy link

hmf commented Feb 16, 2024

Compiler version

Was working with version 3.2.2. Now fails with 3.3.1. Basis for is code was the example in this page.

EDIT: This seems to be working in 3.3.0.

Minimized code

        case '{ List[String].apply(${Varargs(Exprs(elems))}: _*) } =>  
          Some(elems.toList.asInstanceOf[List[T]])

Output

error] -- [E178] Type Error: /home/hmf/VSCodeProjects/sploty/meta/src/icollection/IMap.scala:1753:20 
[error] 1753 |        case '{ List[String].apply(${Varargs(Exprs(elems))}: _*) } =>  
[error]      |                ^^^^^^^^^^^^
[error]      |     missing argument list for method apply in trait IterableFactory
[error]      |
[error]      |       def apply[A](elems: A*): CC[A]
[error]      |--------------------------------------------------------------------------
[error]      | Explanation (enabled by `-explain`)
[error]      |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]      | Unapplied methods are only converted to functions when a function type is expected.
[error]       --------------------------------------------------------------------------
[error] Explanation
[error] ===========
[error] Unapplied methods are only converted to functions when a function type is expected.
[error] -- Error: /home/hmf/VSCodeProjects/sploty/meta/src/icollection/IMap.scala:1753:35 
[error] 1753 |        case '{ List[String].apply(${Varargs(Exprs(elems))}: _*) } =>  
[error]      |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]      |Sequence argument type annotation `*` cannot be used here:
[error]      |the corresponding parameter has type Int which is not a repeated parameter type
[error] -- [E006] Not Found Error: /home/hmf/VSCodeProjects/sploty/meta/src/icollection/IMap.scala:1755:15 
[error] 1755 |          Some(elems.toList.asInstanceOf[List[T]])
[error]      |               ^^^^^
[error]      |               Not found: elems
[error]      |--------------------------------------------------------------------------
[error]      | Explanation (enabled by `-explain`)
[error]      |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]      | The identifier for `elems` is not bound, that is,
[error]      | no declaration for this identifier can be found.
[error]      | That can happen, for example, if `elems` or its declaration has either been
[error]      | misspelt or if an import is missing.
[error]       --------------------------------------------------------------------------
[error] Explanation
[error] ===========
[error] The identifier for `elems` is not bound, that is,
[error] no declaration for this identifier can be found.
[error] That can happen, for example, if `elems` or its declaration has either been
[error] misspelt or if an import is missing.

Expectation

Was hoping no changes were needed for the upgrade.

@hmf hmf added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 16, 2024
@som-snytt
Copy link
Contributor

som-snytt commented Feb 16, 2024

Edit: sorry, I missed that the ticket is for 3.3, I assumed 3.4.

I see -source is required to induce messaging in 3.3.x.

So -source:future-migration warns and -source:future errors:

Welcome to Scala 3.3.1 (21.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> val xs = List("a", "b", "c")
val xs: List[String] = List(a, b, c)

scala> List(xs: _*)
1 warning found
-- Migration Warning: --------------------------------------------------------------------------------------------------
1 |List(xs: _*)
  |         ^
  |         The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead
val res0: List[String] = List(a, b, c)

That is different from my normal expectation about -deprecation and syntax changes. (-help actually announces that deprecation is for APIs, not syntax.) Scala 2 had various policies for deprecation, warning under -Xsource:3 and elevated errors under -Xsource:3-cross. That is because 3 is always the future in Scala 2.

@hmf hmf changed the title Macro matching with Varargs fails: Sequence argument type annotation * cannot be used here Regression macro matching with Varargs fails: Sequence argument type annotation * cannot be used here Feb 17, 2024
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 20, 2024

This error is correct

[error] 1753 |        case '{ List[String].apply(${Varargs(Exprs(elems))}: _*) } =>  
[error]      |                ^^^^^^^^^^^^
[error]      |     missing argument list for method apply in trait IterableFactory
[error]      |
[error]      |       def apply[A](elems: A*): CC[A]

The type argument of the apply should not be added directly on the list List[String](....) is equivalent to List.apply[String](....) and not List[String].apply(....).

The following version work:

    case '{ List.apply[String](${Varargs(Exprs(elems))}: _*) } => ... // derprecated `: _*` syntax

    case '{ List[String](${Varargs(Exprs(elems))}: _*) } => ... // derprecated `: _*` syntax

    case '{ List.apply[String](${Varargs(Exprs(elems))}*) } => ...

    case '{ List[String](${Varargs(Exprs(elems))}*) } => ... // probably the best version

@nicolasstucki nicolasstucki added itype:invalid area:metaprogramming:quotes Issues related to quotes and splices and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 20, 2024
@nicolasstucki
Copy link
Contributor

We do need to update the documentation to avoid using the deprecated : _* syntax.

@nicolasstucki
Copy link
Contributor

Example update in scala/docs.scala-lang#2980

bishabosha pushed a commit to scala/docs.scala-lang that referenced this issue Mar 1, 2024
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:invalid
Projects
None yet
Development

No branches or pull requests

3 participants