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

import exported function from another file lose default parameters #15031

Closed
liewhite opened this issue Apr 26, 2022 · 6 comments · Fixed by #20167
Closed

import exported function from another file lose default parameters #15031

liewhite opened this issue Apr 26, 2022 · 6 comments · Fixed by #20167

Comments

@liewhite
Copy link

Compiler version

3.1.2

Minimized code

from/E.scala

package from

object E {
  def toStr(b: Boolean = true) = {
    b.toString
  }
}

export E.toStr

main.scala

import from.toStr

@main def exportBug = {
  toStr()               //missing argument for parameter b of method toStr in package from: (b: Boolean): String
}

Output

compile error: missing argument for parameter b of method toStr in package from: (b: Boolean): String

Missing default parameters may be a compiler bug?

@liewhite liewhite added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 26, 2022
@pikinier20
Copy link
Contributor

Log from scala-cli:

Compiling project (Scala 3.1.1, JVM)
[error] ./f2.scala:4:3: missing argument for parameter b of method toStr in package from: (b: Boolean): String
[error]   toStr()               //missing argument for parameter b of method toStr in package from: (b: Boolean): String
[error]   ^^^^^^^
Error compiling project (Scala 3.1.1, JVM)
Compilation failed
➜  i15031 scala-cli compile . -S 3.nightly
Downloading Scala 3.2.0-RC1-bin-20220425-ba8dccb-NIGHTLY compiler
Compiling project (Scala 3.2.0-RC1-bin-20220425-ba8dccb-NIGHTLY, JVM)
Compiled project (Scala 3.2.0-RC1-bin-20220425-ba8dccb-NIGHTLY, JVM)
➜  i15031 scala-cli compile . -S 3.1.2    
Compiling project (Scala 3.1.2, JVM)
Compiled project (Scala 3.1.2, JVM)

Seems like this bug has been fixed already. Interestingly, on my side it compiled on 3.1.2 but didn't compile on 3.1.1

@pikinier20
Copy link
Contributor

3.1.2 introduced #14051 which most likely fixed the bug

@liewhite
Copy link
Author

liewhite commented Apr 26, 2022

3.1.2 introduced #14051 which most likely fixed the bug

I use sbt, i'm sure scala version is 3.1.2.

build.sbt

val scala3Version = "3.1.2"

lazy val root = project
  .in(file("."))
  .settings(
    name := "playground",
    version := "0.1.0-SNAPSHOT",

    scalaVersion := scala3Version,
  )

sbt compile command output:

sbt:playground> compile
[info] compiling 1 Scala source to /Users/lee/repos/scala/playground/target/scala-3.1.2/classes ...
[error] -- Error: /Users/lee/repos/scala/playground/src/main/scala/exportBug.scala:4:15 
[error] 4 |  println(toStr())
[error]   |          ^^^^^^^
[error]   |missing argument for parameter b of method toStr in package from: (b: Boolean): String
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

@pikinier20
Copy link
Contributor

pikinier20 commented Apr 26, 2022

The println surrounding the toStr() is crucial. You didn't provide it in minimized example but right now I see it in your compiler log.

I agree, it fails on 3.1.2. Still, it doesn't on newest nightly.

EDIT:
To be sure, I tested in on both scala-cli and sbt, and for the fact got sometimes compilation error on 3.1.2 but it might be related to incremental compilation. Making a clean build always succeeds on 3.1.2 and newest nightly.

Could you try to verify that?

@liewhite
Copy link
Author

The println surrounding the toStr() is crucial. You didn't provide it in minimized example but right now I see it in your compiler log.

I agree, it fails on 3.1.2. Still, it doesn't on newest nightly.

EDIT: To be sure, I tested in on both scala-cli and sbt, and for the fact got sometimes compilation error on 3.1.2 but it might be related to incremental compilation. Making a clean build always succeeds on 3.1.2 and newest nightly.

Could you try to verify that?

Oh, it works with sbt clean compile, tks, i'll close this issue

@pikinier20
Copy link
Contributor

I think we can reopen that as a bug in incremental compilation. It doesn't work very well with exports.

Probably this issue is related to: #11841 .

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

Successfully merging a pull request may close this issue.

4 participants