Skip to content

Commit 70f3eca

Browse files
committed
address review comments
1 parent e404de4 commit 70f3eca

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Symbols.scala

+14-14
Original file line numberDiff line numberDiff line change
@@ -629,19 +629,19 @@ object Symbols extends SymUtils {
629629
newClassSymbol(owner, name, flags, completer, privateWithin, coord, compUnitInfo)
630630
}
631631

632-
/** Same as `newNormalizedClassSymbol` except that `parents` can be a function returning a list of arbitrary
633-
* types which get normalized into type refs and parameter bindings.
632+
/** Same as the other `newNormalizedClassSymbol` except that `parents` can be a function returning a list of arbitrary
633+
* types which get normalized into type refs and parameter bindings and annotations can be assigned in the completer.
634634
*/
635-
def newNormalizedClassSymbolUsingClassSymbolinParents(
635+
def newNormalizedClassSymbol(
636636
owner: Symbol,
637637
name: TypeName,
638638
flags: FlagSet,
639639
parentTypes: Symbol => List[Type],
640-
selfInfo: Type = NoType,
641-
privateWithin: Symbol = NoSymbol,
642-
annotations: List[Tree] = Nil,
643-
coord: Coord = NoCoord,
644-
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): ClassSymbol = {
640+
selfInfo: Type,
641+
privateWithin: Symbol,
642+
annotations: List[Tree],
643+
coord: Coord,
644+
compUnitInfo: CompilationUnitInfo | Null)(using Context): ClassSymbol = {
645645
def completer = new LazyType {
646646
def complete(denot: SymDenotation)(using Context): Unit = {
647647
val cls = denot.asClass.classSymbol
@@ -735,23 +735,23 @@ object Symbols extends SymUtils {
735735
/** Same as `newNormalizedModuleSymbol` except that `parents` can be a function returning a list of arbitrary
736736
* types which get normalized into type refs and parameter bindings.
737737
*/
738-
def newNormalizedModuleSymbolUsingClassSymbolInParents(
738+
def newNormalizedModuleSymbol(
739739
owner: Symbol,
740740
name: TermName,
741741
modFlags: FlagSet,
742742
clsFlags: FlagSet,
743743
parentTypes: ClassSymbol => List[Type],
744744
decls: Scope,
745-
privateWithin: Symbol = NoSymbol,
746-
coord: Coord = NoCoord,
747-
compUnitInfo: CompilationUnitInfo | Null = null)(using Context): TermSymbol = {
745+
privateWithin: Symbol,
746+
coord: Coord,
747+
compUnitInfo: CompilationUnitInfo | Null)(using Context): TermSymbol = {
748748
def completer(module: Symbol) = new LazyType {
749749
def complete(denot: SymDenotation)(using Context): Unit = {
750750
val cls = denot.asClass.classSymbol
751751
val decls = newScope
752-
val parents = parentTypes(cls)
752+
val parents = parentTypes(cls).map(_.dealias)
753753
assert(parents.nonEmpty && !parents.head.typeSymbol.is(dotc.core.Flags.Trait), "First parent must be a class")
754-
denot.info = ClassInfo(owner.thisType, cls, parents.map(_.dealias), decls, TermRef(owner.thisType, module))
754+
denot.info = ClassInfo(owner.thisType, cls, parents, decls, TermRef(owner.thisType, module))
755755
}
756756
}
757757
newModuleSymbol(

Diff for: compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import scala.reflect.TypeTest
2626
import dotty.tools.dotc.core.NameKinds.ExceptionBinderName
2727
import dotty.tools.dotc.transform.TreeChecker
2828
import dotty.tools.dotc.core.Names
29+
import dotty.tools.dotc.util.Spans.NoCoord
2930

3031
object QuotesImpl {
3132

@@ -2728,14 +2729,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
27282729
assert(!conPrivateWithin.exists || conPrivateWithin.isType, "consPrivateWithin must be a type symbol or `Symbol.noSymbol`")
27292730
checkValidFlags(clsFlags.toTypeFlags, Flags.validClassFlags)
27302731
checkValidFlags(conFlags.toTermFlags, Flags.validClassConstructorFlags)
2731-
val cls = dotc.core.Symbols.newNormalizedClassSymbolUsingClassSymbolinParents(
2732+
val cls = dotc.core.Symbols.newNormalizedClassSymbol(
27322733
owner,
27332734
name.toTypeName,
27342735
clsFlags,
27352736
parents,
27362737
selfType.getOrElse(Types.NoType),
27372738
clsPrivateWithin,
2738-
clsAnnotations
2739+
clsAnnotations,
2740+
NoCoord,
2741+
compUnitInfo = null
27392742
)
27402743
val methodType: MethodOrPoly = conMethodType(cls.typeRef)
27412744
def throwShapeException() = throw new Exception("Shapes of conMethodType and conParamFlags differ.")
@@ -2809,14 +2812,17 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
28092812

28102813
def newModule(owner: Symbol, name: String, modFlags: Flags, clsFlags: Flags, parents: Symbol => List[TypeRepr], decls: Symbol => List[Symbol], privateWithin: Symbol): Symbol =
28112814
assert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`")
2812-
val mod = dotc.core.Symbols.newNormalizedModuleSymbolUsingClassSymbolInParents(
2815+
val mod = dotc.core.Symbols.newNormalizedModuleSymbol(
28132816
owner,
28142817
name.toTermName,
28152818
modFlags | dotc.core.Flags.ModuleValCreationFlags,
28162819
clsFlags | dotc.core.Flags.ModuleClassCreationFlags,
28172820
parents,
28182821
dotc.core.Scopes.newScope,
2819-
privateWithin)
2822+
privateWithin,
2823+
NoCoord,
2824+
compUnitInfo = null
2825+
)
28202826
val cls = mod.moduleClass.asClass
28212827
cls.enter(dotc.core.Symbols.newConstructor(cls, dotc.core.Flags.Synthetic, Nil, Nil))
28222828
for sym <- decls(cls) do cls.enter(sym)

Diff for: library/src/scala/quoted/Quotes.scala

+13-3
Original file line numberDiff line numberDiff line change
@@ -3859,7 +3859,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
38593859
*
38603860
* Example usage:
38613861
* ```
3862-
* val name = nameExpr.valueOrAbort
3862+
* val name = "myClass"
38633863
* def decls(cls: Symbol): List[Symbol] =
38643864
* List(Symbol.newMethod(cls, "foo", MethodType(Nil)(_ => Nil, _ => TypeRepr.of[Unit])))
38653865
* val parents = List(TypeTree.of[Object])
@@ -3881,10 +3881,20 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
38813881
* Some('{println(s"Foo method call with (${${Ref(idxSym).asExpr}}, ${${Ref(strSym).asExpr}})")}.asTerm)
38823882
* )
38833883
* val clsDef = ClassDef(cls, parents, body = List(fooDef))
3884-
* val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), List(idxExpr.asTerm, strExpr.asTerm))
3884+
* val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), List('{0}.asTerm, '{string}.asTerm))
38853885
*
38863886
* Block(List(clsDef), Apply(Select(newCls, cls.methodMember("foo")(0)), Nil)).asExprOf[Unit]
38873887
* ```
3888+
* construct the equivalent to
3889+
* ```
3890+
* '{
3891+
* class myClass(idx: Int, str: String) extends Object {
3892+
* def foo() =
3893+
* println(s"Foo method call with $idx, $str")
3894+
* }
3895+
* new myClass(0, "string").foo()
3896+
* }
3897+
* ```
38883898
* @param owner The owner of the class
38893899
* @param name The name of the class
38903900
* @param parents Function returning the parent classes of the class. The first parent must not be a trait.
@@ -3965,7 +3975,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
39653975
* constructs the equivalent to
39663976
* ```
39673977
* '{
3968-
* class myClass[T](val param: T) {
3978+
* class myClass[T](val param: T) extends Object {
39693979
* def getParam: T =
39703980
* println("Calling getParam")
39713981
* param

0 commit comments

Comments
 (0)