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

-Xprint:all doesn't print type parameter bounds in the exported types #13306

Closed
unkarjedy opened this issue Aug 17, 2021 · 1 comment · Fixed by #13372
Closed

-Xprint:all doesn't print type parameter bounds in the exported types #13306

unkarjedy opened this issue Aug 17, 2021 · 1 comment · Fixed by #13372
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc good first issue Perfect for someone who wants to get started contributing itype:enhancement Spree Suitable for a future Spree
Milestone

Comments

@unkarjedy
Copy link
Contributor

Compiler version

3.0.2-RC1

Minimized code

Compile this code with -Xprint:all compiler flag

class MyClass

class MembersContainer {
  type MyType[T <: MyClass] = Comparable[T]
}

object Exports {
  val instance = new MembersContainer
  export instance.*

  type Test = MyClass
  val x: MyType[Test] = new Comparable[Test] {
    override def compareTo(o: Test): Int = 0
  }
}

Output

Notice that for the synthetic type Exports.MyType type bounds are not printed in any phase.
Output example:

scalac: result of ...\src\main\scala\B.scala after typer:

scalac: package <empty> {
  class MyClass() extends Object() {}
  class MembersContainer() extends Object() {
    type MyType[T >: Nothing <: MyClass] = Comparable[T]
  }
  final lazy module val Exports: Exports = new Exports()
  final module class Exports() extends Object() { this: Exports.type =>
    val instance: MembersContainer = new MembersContainer()
    export Exports.instance.*
    final type MyType[T] = Comparable[T]
    type Test = MyClass
    val x: Exports.MyType[Exports.Test] = 
      {
        final class $anon() extends Object(), Comparable[Exports.Test] {
          override def compareTo(o: Exports.Test): Int = 0
        }
        new $anon():Comparable[Exports.Test]
      }
  }
}
...

notice no type parameter bounds

final type MyType[T] = Comparable[T]

However, if you replace type Test = MyClass with e.g. type Test = String the compiler will generate an error, indicating that the type parameter bound is there:

...\src\main\scala\B.scala:12:17
Type argument Exports.Test does not conform to upper bound MyClass
  val x: MyType[Test] = new Comparable[Test] {

Expectation

The type parameter bounds are printed for the exported synthetic members

@bishabosha bishabosha added itype:enhancement area:reporting Error reporting including formatting, implicit suggestions, etc good first issue Perfect for someone who wants to get started contributing Spree Suitable for a future Spree and removed itype:bug labels Aug 17, 2021
@unkarjedy
Copy link
Contributor Author

Looks like this comment is outdated?
https://github.com/lampepfl/dotty/blob/b7b47463c3397104ca92fbe5bd085a00d423b9fc/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1105

Note: This will always create unparameterzied aliases. So even if the original type is
a parameterized class, say C[X] the alias will read type C = d.C. We currently do
allow such type aliases. If we forbid them at some point (requiring the referred type to be
fully applied), we'd have to change the scheme here as well.

Aliases are parametrized

@adpi2 adpi2 self-assigned this Aug 23, 2021
adpi2 added a commit to adpi2/scala3 that referenced this issue Aug 24, 2021
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
adpi2 added a commit to adpi2/scala3 that referenced this issue Aug 24, 2021
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
adpi2 added a commit to adpi2/scala3 that referenced this issue Aug 24, 2021
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
adpi2 added a commit to adpi2/scala3 that referenced this issue Aug 24, 2021
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
adpi2 added a commit to adpi2/scala3 that referenced this issue Aug 24, 2021
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
Co-authored-by: Jamie Thompson <jamie.thompson@bath.edu>
Co-authored-by: Meriam Lachkar <meriam.lachkar@gmail.com>
@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc good first issue Perfect for someone who wants to get started contributing itype:enhancement Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants