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

Invalid return type when using default method parameters on non-stable instances #9611

Open
scabug opened this issue Jan 7, 2016 · 4 comments

Comments

@scabug
Copy link

scabug commented Jan 7, 2016

The following code fails to compile.

The failure happens when a method has a default parameter, has a return type depending on one of its parameters; when the method itself is not called from a stable identifier.

See code below, the failure pattern is the same for all Scala version affected.

trait Container[S <: Seq[Int] with Singleton] {
  val s: S
}

trait Builder {
  def withoutDefault(s0: Seq[Int]): Container[s0.type] = new Container[s0.type] {
    val s: s0.type = s0
  }
  def withDefault(s0: Seq[Int], i: Int = 0): Container[s0.type] = withoutDefault(s0)
}

object Builder {
  val instance1 = new Builder { }
  def instance2 = new Builder { }
}

object Builder1 {
  def withoutDefault(s0: Seq[Int]): Container[s0.type] = new Container[s0.type] {
    val s: s0.type = s0
  }
  def withDefault(s0: Seq[Int], i: Int = 0): Container[s0.type] = withoutDefault(s0)
}

object Test {
  val seq = Seq(1, 2, 3, 4)
  val works1: Container[seq.type] = Builder1.withoutDefault(seq)
  val works2: Container[seq.type] = Builder1.withDefault(seq, 0)
  val works3: Container[seq.type] = Builder1.withDefault(seq)

  val works4: Container[seq.type] = Builder.instance1.withoutDefault(seq)
  val works5: Container[seq.type] = Builder.instance1.withDefault(seq, 0)
  val works6: Container[seq.type] = Builder.instance1.withDefault(seq)

  val works7: Container[seq.type] = Builder.instance2.withoutDefault(seq)
  val works8: Container[seq.type] = Builder.instance2.withDefault(seq, 0)
  val fails: Container[seq.type] = Builder.instance2.withDefault(seq)
}
@scabug
Copy link
Author

scabug commented Jan 7, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9611?orig=1
Reporter: Denis Rosset (denisrosset)
Affected Versions: 2.10.6, 2.11.8, 2.12.0-RC1

@scabug
Copy link
Author

scabug commented Sep 29, 2016

@SethTisue said:
what's the compiler say?

@scabug
Copy link
Author

scabug commented Sep 30, 2016

Denis Rosset (denisrosset) said:

[error] /home/denis/Documents/test/Test.scala:36: type mismatch;
[error]  found   : Container[x$1.type]
[error]  required: Container[Test.seq.type]
[error]   val fails: Container[seq.type] = Builder.instance2.withDefault(seq)

@scabug
Copy link
Author

scabug commented Sep 30, 2016

Denis Rosset (denisrosset) said:
BTW, this is on 2.10.6 and 2.11.8, and also on 2.12.0-RC1.

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

No branches or pull requests

1 participant