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

Accessing backqouted underscore does not parse but compiles fine in Scala 2.13.x #14746

Open
romanowski opened this issue Mar 22, 2022 · 4 comments

Comments

@romanowski
Copy link
Contributor

Compiler version

I tested with3.1.1 but it probably applies to all Scala 3 / dotty versions

Minimized code

//> using lib "com.lihaoyi:scalaparse_2.13:2.3.3"

import fastparse._

class U extends App {
  def a[T: P] = scalaparse.Scala.`_` 
                                                    // ^ fails here with: wildcard invalid as backquoted identifier
}

Output

Compiles on Scala 2.13.8, fails on 3.1.1 with:

[error] ./underscore.scala:6:34: wildcard invalid as backquoted identifier
[error]   def a[T: P] = scalaparse.Scala.`_`
[error]                                  ^
Error compiling project (Scala 3.1.1, JVM)

Expectation

I know that_ is not the best name of the method, however, it exists and is used e.g. in Scala CLI.

@romanowski romanowski added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 22, 2022
@romanowski romanowski changed the title Accessing def _ does not parse but compiles fine in Scala 2.13.x Accessing def `` _ `` does not parse but compiles fine in Scala 2.13.x Mar 22, 2022
@romanowski romanowski changed the title Accessing def `` _ `` does not parse but compiles fine in Scala 2.13.x Accessing backqouted underscore does not parse but compiles fine in Scala 2.13.x Mar 22, 2022
@som-snytt
Copy link
Contributor

This has a long history on Scala 2, where support was for what version of Java allowed underscore.

The dotty behavior is noted at scala/bug#10384 (comment)

The import behavior was supported at scala/scala#6218

In a definition scala/scala#7669

I wonder if you're allowed to have a class named underscore.

@Kordyjan Kordyjan added area:parser stat:needs spec and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 23, 2022
@odersky
Copy link
Contributor

odersky commented Mar 23, 2022

_ has a special meaning in the compiler. It should not be treated as a regular identifier. The situations where we still treat it as an identifier are probably all bugs or at least in some form problematic.

What is the use case in scala-cli?

@Kordyjan
Copy link
Contributor

The problem here seems to be the fact that Scala 2.13 libraries were using _ as a function name and now they are unusable from Scala 3. Here is the one that caused the problem in scala-cli.

@odersky
Copy link
Contributor

odersky commented Mar 23, 2022

The fastparse code treats _ like a keyword. Problem is, the tree does not reflect this. _ is treated as Ident("_"). So backquoting is very tricky. Maybe we can make it work in only 3.0-migration mode? Would that work for scala-cli?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants