[2.x] Update Eval.compileAndLoad (#9583)

This commit is contained in:
kenji yoshida 2026-08-13 12:33:08 +09:00 committed by GitHub
parent 784d116bd4
commit a6ae53c73e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 8 deletions

View File

@ -278,19 +278,37 @@ class Eval(
case template: tpd.Template =>
template.body.foreach {
case defdef: tpd.DefDef if defdef.name.mangledString == WrapValName =>
defdef.rhs match {
case tpd.Block(
(typeDef: tpd.TypeDef) :: Nil,
ast.untpd.Literal(Constants.Constant(()))
) =>
PartialFunction
.condOpt(defdef.rhs) {
case tpd.Block(
(typeDef: tpd.TypeDef) :: Nil,
ast.untpd.Literal(Constants.Constant(()))
) =>
// class
typeDef.sourcePos
case tpd.Block(
(valDef: tpd.ValDef) :: (typeDef: tpd.TypeDef) :: Nil,
ast.untpd.Literal(Constants.Constant(()))
) if valDef.tpt.tpe =:= typeDef.tpe =>
// object
typeDef.sourcePos
case tpd.Block(
(typeDef1: tpd.TypeDef) :: (valDef: tpd.ValDef) :: (typeDef2: tpd.TypeDef) :: Nil,
ast.untpd.Literal(Constants.Constant(()))
)
if (valDef.tpt.tpe =:= typeDef2.tpe) && (s"${typeDef1.name.mangledString}${NameTransformer.MODULE_SUFFIX_STRING}" ==
typeDef2.name.mangledString) =>
// enum, case class
typeDef1.sourcePos
}
.foreach { pos =>
reporter.report(
Diagnostic.Error(
"Defining types in *.sbt file is not supported",
typeDef.sourcePos
pos
)
)
case _ =>
}
}
case _ =>
}
case _ =>