Ammonite icon indicating copy to clipboard operation
Ammonite copied to clipboard

@main does not work on scala 3.0.0 (homebrew installation)

Open dmgerman opened this issue 3 years ago • 5 comments

homebrew is installing scala 3.0.0

% amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 3.0.0 Java 16.0.1)
@  

%amm rip7.sc --i 5 --s 'abc'    
hello 2
Script rip7.sc does not take arguments: "--i" "5" "--s" "abc"


and the script is:

% more rip7.sc 
val x = 1

@main
def main(i: Int, s: String, path: os.Path = os.pwd) = {
  println("hello");
  s"Hello! ${s * i} ${path.last}."
}
println("hello 2");

however, this script works when I download ammonite directly (it uses scala 2.13)

% ~/amm
Loading...
Welcome to the Ammonite Repl 2.4.0 (Scala 2.13.6 Java 17)
@  

% ~/amm rip7.sc -i 5 -s 'abc'                                                            
hello 2
hello
"Hello! abcabcabcabcabc tmp."

dmgerman avatar Jun 28 '21 21:06 dmgerman

I can confirm this: it works with Ammonite 2.4.0 and Scala 2.13, but not with the combination 2.4.0 and Scala 3.0.

$ amm3 re1.sc all
Script re1.sc does not take arguments: "all"

This is independent of homebrew. I generated the amm3 above with

sudo sh -c '(echo "#!/usr/bin/env sh" && curl -L https://github.com/com-lihaoyi/Ammonite/releases/download/2.4.0/3.0-2.4.0) > /usr/local/bin/amm3 && chmod +x /usr/local/bin/amm3' && amm3

urbanchr avatar Aug 30 '21 15:08 urbanchr

I've encountered this bug as well. For an identical script, it works correctly on Ammonite w/2.13, but does not pick up the @main function on Ammonite w/3.

Tested on Ammonite 2.4.0 with AdoptOpenJDK 11.0.11

TJC avatar Sep 10 '21 03:09 TJC

I've opened a discussion on Homebrew to ask if the version there can be reverted to the stable 2.13-2.4.0 version: https://github.com/Homebrew/discussions/discussions/2117

TJC avatar Sep 10 '21 03:09 TJC

@lihaoyi Is there any way to get arguments in ammonite script with scala 3.x?

zhranklin avatar Jan 12 '22 05:01 zhranklin

This might be related to #1150.

See also: https://contributors.scala-lang.org/t/plan-for-main-and-mainargs-in-scala3/4897

edwardcwang avatar Jan 31 '22 16:01 edwardcwang

this may fix it: https://github.com/com-lihaoyi/Ammonite/pull/1298

mpollmeier avatar Oct 07 '22 15:10 mpollmeier