Skip to content

Fix bug which prevented New over type-instantiated aliases. #384

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

Merged
merged 1 commit into from
Mar 2, 2015

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 28, 2015

Previously,

 type Map = HashMap[Int, String]
 new Map

did not work. See test aliasNew.scala for a test.
Formerly this logic handled in Parsers (wrapNew),
but that one does not work for aliastypes.

Review by @DarkDimius

Previously,

     type Map = HashMap[Int, String]
     new Map

did not work. See test aliasNew.scala for a test.
Formerly this logic handled in Parsers (wrapNew),
but that one does not work for aliastypes.
@DarkDimius
Copy link
Contributor

LGTM

DarkDimius added a commit that referenced this pull request Mar 2, 2015
Fix bug which prevented New over type-instantiated aliases.
@DarkDimius DarkDimius merged commit 3a6cab4 into scala:master Mar 2, 2015
@retronym
Copy link
Member

retronym commented Mar 2, 2015

% cat sandbox/test.scala
class Map[A, B]
class A {
  type M = Map[Int, String]
}

object Test {
  val a = new A
  val b = new a.M
}

% ../dotty/bin/dotc -Xprint:frontend sandbox/test.scala
result of sandbox/test.scala after frontend:
package <empty> {
  class Map[A, B]()  extends Object() {
    Map$$A
    private[this] type A = Map$$A
    Map$$B
    private[this] type B = Map$$B
  }
  class A()  extends Object() {
    type M = Map[Int, String]
  }
  final lazy module val Test: Test$ = new Test$()
  final module class Test$()  extends Object() { this: Test.type =>
    val a: A = new A()
    val b: Map[Int, String] = new Test.a.M[Int, String]()
  }
}

Shouldn't this be:

val b: Map[Int, String] = new Map[Int, String]()

@retronym
Copy link
Member

retronym commented Mar 2, 2015

Probably relatedly, this doesn't typecheck:

class Map[A, B]
class A {
  type M[A] = Map[Int, A]
}

object Test {
  val a = new A
  val b = new a.M // error: wrong number of type parameters for [A, B]()Map[A, B](Test.a.M#<init>); expected: 2
}

@allanrenucci allanrenucci deleted the fix/constructor-alias branch December 14, 2017 19:22
tgodzik added a commit to tgodzik/scala3 that referenced this pull request May 2, 2025
Backport "No warn for evidence params of marker traits such as NotGiven" to 3.3 LTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants