-
-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Scala3] Unable to define extension methods in REPL #1281
Comments
@tanishiking I think that's the right part of the codebase that needs tweaking. Feel free to fix it, yes! |
tanishiking
added a commit
to tanishiking/Ammonite
that referenced
this issue
Aug 16, 2022
fix: com-lihaoyi#1281 Previously, ammonite REPL couldn't define extension methods because of the lack of Preprocessor for extension method definition. ``` ❯ scala-cli repl --scala 3.1.3 --ammonite Loading... Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 17.0.3) @ extension (foo: Int) def bar = foo -- [E006] Not Found Error: cmd0.sc:1:11 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^^^^^^^ | Not found: extension | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:1:22 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:2:12 ---------------------------------------- 2 | def bar = foo | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` Compilation Failed ``` Now, this is possible to define extension methods in Ammonite REPL. ``` Welcome to the Ammonite Repl 2.5.4-14-dc4c47bc (Scala 3.1.3 Java 1.8.0_302) @ extension (foo: Int) def x = 1 def y = 1 defined extension methods @ 100.x res1: Int = 1 ```
tanishiking
added a commit
to tanishiking/Ammonite
that referenced
this issue
Aug 18, 2022
fix: com-lihaoyi#1281 Previously, ammonite REPL couldn't define extension methods because of the lack of Preprocessor for extension method definition. ``` ❯ scala-cli repl --scala 3.1.3 --ammonite Loading... Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 17.0.3) @ extension (foo: Int) def bar = foo -- [E006] Not Found Error: cmd0.sc:1:11 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^^^^^^^ | Not found: extension | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:1:22 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:2:12 ---------------------------------------- 2 | def bar = foo | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` Compilation Failed ``` Now, this is possible to define extension methods in Ammonite REPL. ``` Welcome to the Ammonite Repl 2.5.4-14-dc4c47bc (Scala 3.1.3 Java 1.8.0_302) @ extension (foo: Int) def x = 1 def y = 1 defined extension methods @ 100.x res1: Int = 1 ```
alexarchambault
pushed a commit
that referenced
this issue
Aug 18, 2022
fix: #1281 Previously, ammonite REPL couldn't define extension methods because of the lack of Preprocessor for extension method definition. ``` ❯ scala-cli repl --scala 3.1.3 --ammonite Loading... Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 17.0.3) @ extension (foo: Int) def bar = foo -- [E006] Not Found Error: cmd0.sc:1:11 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^^^^^^^ | Not found: extension | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:1:22 ---------------------------------------- 1 |val res0 = extension (foo: Int) | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` -- [E006] Not Found Error: cmd0.sc:2:12 ---------------------------------------- 2 | def bar = foo | ^^^ | Not found: foo | | longer explanation available when compiling with `-explain` Compilation Failed ``` Now, this is possible to define extension methods in Ammonite REPL. ``` Welcome to the Ammonite Repl 2.5.4-14-dc4c47bc (Scala 3.1.3 Java 1.8.0_302) @ extension (foo: Int) def x = 1 def y = 1 defined extension methods @ 100.x res1: Int = 1 ```
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
It would be nice if we can define extension methods as normal REPL can do that
It looks like the problem is, the preprocessor for Scala3 doesn't expect to have the
extension keyword
hereAmmonite/amm/compiler/src/main/scala-3/ammonite/compiler/Preprocessor.scala
Lines 256 to 258 in dc4c47b
I'm new to the Ammonite codebase, but I'm willing to contribute to this :)
The text was updated successfully, but these errors were encountered: