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

3.1.2 compiler emits an error - Type argument B does not conform to lower bound String for export of a Seq value #14953

Closed
chungonn opened this issue Apr 17, 2022 · 4 comments · Fixed by #14963
Assignees
Milestone

Comments

@chungonn
Copy link

The following code compiles in Scala 3.1.1 and with Scala 3.1.2, the compiler emits the following error - Type argument B does not conform to lower bound String

object Test{
  
  val xs: Seq[String] = List("Apple", "Orange", "Pear")
  export xs.*
  
} 

Test.head
@chungonn chungonn added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 17, 2022
@som-snytt
Copy link
Contributor

som-snytt commented Apr 17, 2022

It looks like the bound on a default arg method.

    final def lastIndexOf[B >: String](elem: B, end: Int): Int = X.xs.lastIndexOf[B](elem, end)
    final def lastIndexOf$default$2[B >: A]: Int @uncheckedVariance = X.xs.lastIndexOf$default$2[B]

Or, minimized

class C[A] {
  def f[B >: A](x: Int = 42): A = ???
}
object X {
  val c = new C[String]
  export c.*
}

which looks like

  @SourceFile("exp0.scala") class C[A >: Nothing <: Any]() extends Object() {
    A
    def f[B >: C.this.A <: Any](x: Int): C.this.A = ???
    def f$default$1[B >: C.this.A <: Any]: Int @uncheckedVariance = 42
  }
  final lazy module val X: X = new X()
  @SourceFile("exp0.scala") final module class X() extends Object() { this: X.type =>
    private def writeReplace(): AnyRef = new scala.runtime.ModuleSerializationProxy(classOf[X.type])
    val c: C[String] = new C[String]()
    export X.c.*
    final def f[B >: String](x: Int): String = X.c.f[B](x)
    final def f$default$1[B >: A]: Int @uncheckedVariance = X.c.f$default$1[B]
  }

For an error in synthetic code where the caret isn't helpful, it would be nice if the message could capture enough context (such as the enclosing definition) to pretty print with the caret.

@chungonn
Copy link
Author

chungonn commented Apr 18, 2022

My code uses only the Seq#head method and when I did the export xs.head my application compiles. I suppose the method resolution for export in Scala 3.1.2 is different Scala 3.1.1

I realised the export xs.* declaration alone has compilation error.

@som-snytt
Copy link
Contributor

My comment explains that the export exports the wrong signature for the default arg methods. The signature includes the type param of the "source" method even if not used, and the bound should be [B :> String] in the examples.

@chungonn
Copy link
Author

Noted with thanks. I thought I could provide more context on my export usage :)

odersky added a commit to dotty-staging/dotty that referenced this issue Apr 18, 2022
@odersky odersky removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Apr 18, 2022
@odersky odersky self-assigned this Apr 18, 2022
michelou pushed a commit to michelou/dotty that referenced this issue Apr 25, 2022
@Kordyjan Kordyjan added this to the 3.2.0 milestone Aug 1, 2023
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