Skip to content

Commit 52e0560

Browse files
committed
Fix #4557 rework: Keep original type untpd.New
We need to keep the original type - to allow IDE naviagtion - to make PrepareTransparent work correctly
1 parent 101daf5 commit 52e0560

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -301,20 +301,23 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
301301

302302
// ------ Additional creation methods for untyped only -----------------
303303

304-
/** new pre.C[Ts](args1)...(args_n)
304+
/** new T(args1)...(args_n)
305305
* ==>
306-
* (new pre.C).<init>[Ts](args1)...(args_n)
306+
* new T.<init>[Ts](args1)...(args_n)
307+
*
308+
* where `Ts` are the class type arguments of `T` or its class type alias.
309+
* Note: we also keep any type arguments as parts of `T`. This is necessary to allow
310+
* navigation into these arguments from the IDE, and to do the right thing in
311+
* PrepareTransparent.
307312
*/
308313
def New(tpt: Tree, argss: List[List[Tree]])(implicit ctx: Context): Tree = {
309314
val (tycon, targs) = tpt match {
310315
case AppliedTypeTree(tycon, targs) =>
311316
(tycon, targs)
312317
case TypedSplice(tpt1: tpd.Tree) =>
313-
val tp = tpt1.tpe.dealias
314-
val tycon = tp.typeConstructor
315-
val argTypes = tp.argTypesLo
316-
def wrap(tpe: Type) = TypeTree(tpe) withPos tpt.pos
317-
(wrap(tycon), argTypes map wrap)
318+
val argTypes = tpt1.tpe.dealias.argTypesLo
319+
def wrap(tpe: Type) = TypeTree(tpe).withPos(tpt.pos)
320+
(tpt, argTypes.map(wrap))
318321
case _ =>
319322
(tpt, Nil)
320323
}

tests/neg/wildbase.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A[T]
22

3-
class B extends A[_] // OK
3+
class B extends A[_] // error: type argument must be fully defined
44

5-
class C extends A[_ >: Any <: Nothing] // error: conflicting bounds
5+
class C extends A[_ >: Any <: Nothing] // error: conflicting bounds // error: type argument must be fully defined

tests/run/tasty-extractors-2.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Type.SymRef(ClassDef("Unit", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("
9191
Term.Block(List(ClassDef("Foo12", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.Synthetic()), "<init>", Some(Signature(Nil, java.lang.Object))), Nil)), None, List(ValDef("a", TypeTree.Synthetic(), Some(Term.Literal(Constant.Int(11))))))), Term.Literal(Constant.Unit()))
9292
Type.SymRef(ClassDef("Unit", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("scala", _), NoPrefix())))
9393

94-
Term.Block(List(ClassDef("Foo", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.Synthetic()), "<init>", Some(Signature(Nil, java.lang.Object))), Nil)), None, Nil), ClassDef("Bar", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.Synthetic()), "<init>", Some(Signature(Nil, Test$._$Foo))), Nil)), None, Nil)), Term.Literal(Constant.Unit()))
94+
Term.Block(List(ClassDef("Foo", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.Synthetic()), "<init>", Some(Signature(Nil, java.lang.Object))), Nil)), None, Nil), ClassDef("Bar", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.TypeIdent("Foo")), "<init>", Some(Signature(Nil, Test$._$Foo))), Nil)), None, Nil)), Term.Literal(Constant.Unit()))
9595
Type.SymRef(ClassDef("Unit", _, _, _, _), Type.ThisType(Type.SymRef(PackageDef("scala", _), NoPrefix())))
9696

9797
Term.Block(List(ClassDef("Foo2", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(TypeTree.Synthetic()), None, Nil), ClassDef("Bar", DefDef("<init>", Nil, List(Nil), TypeTree.Synthetic(), None), List(Term.Apply(Term.Select(Term.New(TypeTree.Synthetic()), "<init>", Some(Signature(Nil, java.lang.Object))), Nil), TypeTree.TypeIdent("Foo2")), None, Nil)), Term.Literal(Constant.Unit()))

0 commit comments

Comments
 (0)