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

Inconsistent hygiene of type parameters and parameter types of case apply / unapply / copy #8884

Open
scabug opened this issue Oct 6, 2014 · 3 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone

Comments

@scabug
Copy link

scabug commented Oct 6, 2014

The parameter types of case class apply / unapply are not hygienic

scala> case class C(x: String); object C { class String }
<console>:7: error: type mismatch;
 found   : C.String
 required: java.lang.String
       case class C(x: String); object C { class String }
                  ^

The parameter types of copy are hygienic. This is inconsistent, and also the implementation is very complex (custom type completer). Hygiene was required for copy because it fails more often, namely in this example

class A {
  class C
  case class B(x: C) extends A { def copy(x: C = this.x) = ... }
}

Note that B extends A, so the constructor parameter is A.this.C, while the copy parameter is B.this.C.

Type parameters of copy are not hygienic, as shown in this example:

scala> case class C[T <: String]() { class String }
<console>:7: error: type arguments [T] do not conform to class C's type parameter bounds [T <: String]
       case class C[T <: String]() { class String }
                  ^

Fixing this bug also requires clarifying the corresponding section in the spec

@scabug
Copy link
Author

scabug commented Oct 6, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8884?orig=1
Reporter: @lrytz
Affected Versions: 2.11.2

@scabug
Copy link
Author

scabug commented Nov 3, 2014

@lrytz said:
This is fixed in dotty, all parameter types / type parameter bounds are hygienic

https://github.com/lampepfl/dotty/blob/master/src/dotty/tools/dotc/ast/Desugar.scala#L298

@scabug
Copy link
Author

scabug commented Nov 6, 2014

@retronym said:
Here's another example, brought up on the mailing list (https://groups.google.com/d/msg/scala-language/DDpvGcrs3QQ/kGWFJFDvkqQJ)

        case class A(b:B = bb)

        case class B(i: Int, j: Int)

        object bb extends B(3, 4)

        object A {

                val bb = new B(7, 2)
        }

        println(A())
        println(new A())

This code will print:

        A(B(7,2))
        A(B(3,4))

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

3 participants