Skip to content

import exported function from another file lose default parameters #15031

@liewhite

Description

@liewhite

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?

Activity

pikinier20

pikinier20 commented on Apr 26, 2022

@pikinier20
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

pikinier20 commented on Apr 26, 2022

@pikinier20
Contributor

3.1.2 introduced #14051 which most likely fixed the bug

liewhite

liewhite commented on Apr 26, 2022

@liewhite
Author

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

pikinier20 commented on Apr 26, 2022

@pikinier20
Contributor

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

liewhite commented on Apr 26, 2022

@liewhite
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

pikinier20 commented on Apr 26, 2022

@pikinier20
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 .

3 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @liewhite@Kordyjan@bishabosha@pikinier20

    Issue actions

      import `export`ed function from another file lose default parameters · Issue #15031 · scala/scala3