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

Problem running @main methods with command line arguments #14541

Closed
spamegg1 opened this issue Feb 22, 2022 · 5 comments · Fixed by #14543
Closed

Problem running @main methods with command line arguments #14541

spamegg1 opened this issue Feb 22, 2022 · 5 comments · Fixed by #14543
Labels
itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@spamegg1
Copy link

spamegg1 commented Feb 22, 2022

Compiler version

3.1.1

Minimized code

// In file echoargs.scala
@main def echo(args: String*) =
  println(args.mkString(" "))

Output

First compile

$ scalac echoargs.scala

Then run the main method:

$ scala echo hello world
echo hello world hello world

Expectation

$ scala echo hello world
hello world

Edit: this was the output using the scala command of 3.0.2

@spamegg1
Copy link
Author

Similarly, for this file

// In file repeatword.scala
@main def repeat(word: String, count: Int) =
  println(List.fill(count)(word).mkString(" "))

Output

First compile

$ scalac repeatword.scala

Then run the main method:

$ scala repeat hello 3
Illegal command line after first argument: java.lang.NumberFormatException: For input string: "hello"

However:

$ scala repeat 3
repeat repeat repeat

Expectation

$ scala repeat hello 3
hello hello hello

@som-snytt
Copy link
Contributor

PR is quick tweak. Key phrase from last summer: "MainGenericRunner should work almost ".

If we can go 6 months without using command line args, then maybe we don't need command line args.

@som-snytt
Copy link
Contributor

$ scala echo hello world
echo hello world hello world

Crossword just had clue "hello hello hello, e.g." for "echo".

@spamegg1
Copy link
Author

If we can go 6 months without using command line args, then maybe we don't need command line args.

The book told me to do it! (Prog in Scala 5th ed) It's used to show the power of type classes:

How does Scala know how to turn the command line string "3" into
an Int 3 ? It uses a typeclass named FromString ,

@bishabosha
Copy link
Member

bishabosha commented Feb 22, 2022

the scala command was ported from bash to Scala in 3.1.0 - this did work as expected with the scala command of 3.0.2

@bishabosha bishabosha added the regression This worked in a previous version but doesn't anymore label Feb 22, 2022
@nicolasstucki nicolasstucki removed their assignment Feb 24, 2022
@Kordyjan Kordyjan added this to the 3.1.3 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

5 participants