Skip to content

Minor architectural clean-up #6941

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions compiler/src/dotty/tools/backend/sjs/JUnitBootstrappers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ class JUnitBootstrappers extends MiniPhase {
val testAnnot = test.getAnnotation(junitdefn.TestAnnotClass).get
if (testAnnot.arguments.nonEmpty)
ctx.error("@Test annotations with arguments are not yet supported in Scala.js for dotty", testAnnot.tree.sourcePos)
val noArgConstr = junitdefn.TestAnnotType.member(nme.CONSTRUCTOR).suchThat(_.info.paramInfoss.head.isEmpty).symbol.asTerm
val reifiedAnnot = New(junitdefn.TestAnnotType, noArgConstr, Nil)
val reifiedAnnot = resolveConstructor(junitdefn.TestAnnotType, Nil)
New(junitdefn.TestMetadataType, List(name, ignored, reifiedAnnot))
}
JavaSeqLiteral(metadata, TypeTree(junitdefn.TestMetadataType))
Expand All @@ -250,11 +249,7 @@ class JUnitBootstrappers extends MiniPhase {
ValDef(castInstanceSym, instanceParamRef.cast(testClass.typeRef)) :: Nil,
tests.foldRight[Tree] {
val tp = junitdefn.NoSuchMethodExceptionType
val constr = tp.member(nme.CONSTRUCTOR).suchThat { c =>
c.info.paramInfoss.head.size == 1 &&
c.info.paramInfoss.head.head.isRef(defn.StringClass)
}.symbol.asTerm
Throw(New(tp, constr, nameParamRef :: Nil))
Throw(resolveConstructor(tp, nameParamRef :: Nil))
} { (test, next) =>
If(Literal(Constant(test.name.toString)).select(defn.Any_equals).appliedTo(nameParamRef),
genTestInvocation(testClass, test, ref(castInstanceSym)),
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1362,5 +1362,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
transformer.transform(tree)
}

def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
val targs = atp.argTypes
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
}
}

9 changes: 0 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ object Annotations {
def apply(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation =
apply(New(atp, args))

private def resolveConstructor(atp: Type, args:List[Tree])(implicit ctx: Context): Tree = {
val targs = atp.argTypes
tpd.applyOverloaded(New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
}

def applyResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = {
apply(resolveConstructor(atp, args))
}

/** Create an annotation where the tree is computed lazily. */
def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation =
new LazyAnnotation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
}
t.toList
}
// println(atp)
val targs = atp.argTypes

tpd.applyOverloaded(tpd.New(atp.typeConstructor), nme.CONSTRUCTOR, args, targs, atp)
}
resolveConstructor(atp, args)
}

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