Skip to content

Regression: new <type alias> should compile #11781

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

Closed
japgolly opened this issue Mar 17, 2021 · 2 comments · Fixed by #11788
Closed

Regression: new <type alias> should compile #11781

japgolly opened this issue Mar 17, 2021 · 2 comments · Fixed by #11788
Milestone

Comments

@japgolly
Copy link
Contributor

Compiler version

3.0.0-RC1

Minimized code

object Ah {
  final case class Values[B, +A](a: A)

  trait Object[B] {
    final type Values[+A] = Ah.Values[B, A]
    object Values {
      def blah: Values[Unit] =
        new Values(())
    }
  }
}

Output

-- Error: as.scala:8:12 --------------------------------------------------------
8 |        new Values(())
  |            ^^^^^^
  |            Object.this.Values is not a class type
-- Error: as.scala:8:19 --------------------------------------------------------
8 |        new Values(())
  |                   ^^
  |     too many arguments for constructor Object in class Object: (): Object
2 errors found

Expectation

It should compile. It compiles with Scala 2.12 and 2.13.

@odersky
Copy link
Contributor

odersky commented Mar 17, 2021

Further minimization:

object Test:
  class C1[A](a: A)
  type D1[A] = C1[A]
  new D1(1)    // works

  class C2[B, A](a: A)
  type D2[A] = C2[Int, A]
  new D2(1)    // error

The problem arises if the type alias does not simply forward all its type parameters to the class.

@odersky
Copy link
Contributor

odersky commented Mar 17, 2021

As a workaround you can explicitly pass the type argument.

new D2[Int](1)   // works

The problem is that at the time we typecheck the new we do not have the inferred type. And just looking at D2 it's not true that this is an alias of C2. Hence the failure.

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.

3 participants