Skip to content

Commit 54b6234

Browse files
Close lampepfl/dotty-knowledge#11: Share code from Annotations
1 parent cf1c168 commit 54b6234

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,7 @@ class JUnitBootstrappers extends MiniPhase {
250250
ValDef(castInstanceSym, instanceParamRef.cast(testClass.typeRef)) :: Nil,
251251
tests.foldRight[Tree] {
252252
val tp = junitdefn.NoSuchMethodExceptionType
253-
val constr = tp.member(nme.CONSTRUCTOR).suchThat { c =>
254-
c.info.paramInfoss.head.size == 1 &&
255-
c.info.paramInfoss.head.head.isRef(defn.StringClass)
256-
}.symbol.asTerm
257-
Throw(New(tp, constr, nameParamRef :: Nil))
253+
Throw(resolveConstructor(tp, nameParamRef :: Nil))
258254
} { (test, next) =>
259255
If(Literal(Constant(test.name.toString)).select(defn.Any_equals).appliedTo(nameParamRef),
260256
genTestInvocation(testClass, test, ref(castInstanceSym)),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,5 +1362,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
13621362
}
13631363
transformer.transform(tree)
13641364
}
1365+
1366+
def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
1367+
val targs = atp.argTypes
1368+
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
1369+
}
13651370
}
13661371

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,6 @@ object Annotations {
115115
def apply(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
116116
apply(New(atp, args))
117117

118-
private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
119-
val targs = atp.argTypes
120-
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
121-
}
122-
123118
/** Create an annotation where the tree is computed lazily. */
124119
def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
125120
new LazyAnnotation {

compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
934934
}
935935
t.toList
936936
}
937-
// println(atp)
938-
val targs = atp.argTypes
939-
940-
tpd.applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
941-
}
937+
resolveConstructor(atp, args)
938+
}
942939

943940
/** Read an annotation and as a side effect store it into
944941
* the symbol it requests. Called at top-level, for all

0 commit comments

Comments
 (0)