Skip to content

Commit 8190f1c

Browse files
committed
address review comments
1 parent 32f484a commit 8190f1c

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

@@ -2691,14 +2692,16 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
26912692
assert(!conPrivateWithin.exists || conPrivateWithin.isType, "consPrivateWithin must be a type symbol or `Symbol.noSymbol`")
26922693
checkValidFlags(clsFlags.toTypeFlags, Flags.validClassFlags)
26932694
checkValidFlags(conFlags.toTermFlags, Flags.validClassConstructorFlags)
2694-
val cls = dotc.core.Symbols.newNormalizedClassSymbolUsingClassSymbolinParents(
2695+
val cls = dotc.core.Symbols.newNormalizedClassSymbol(
26952696
owner,
26962697
name.toTypeName,
26972698
clsFlags,
26982699
parents,
26992700
selfType.getOrElse(Types.NoType),
27002701
clsPrivateWithin,
2701-
clsAnnotations
2702+
clsAnnotations,
2703+
NoCoord,
2704+
compUnitInfo = null
27022705
)
27032706
val methodType: MethodOrPoly = conMethodType(cls.typeRef)
27042707
def throwShapeException() = throw new Exception("Shapes of conMethodType and conParamFlags differ.")
@@ -2772,14 +2775,17 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
27722775

27732776
def newModule(owner: Symbol, name: String, modFlags: Flags, clsFlags: Flags, parents: Symbol => List[TypeRepr], decls: Symbol => List[Symbol], privateWithin: Symbol): Symbol =
27742777
assert(!privateWithin.exists || privateWithin.isType, "privateWithin must be a type symbol or `Symbol.noSymbol`")
2775-
val mod = dotc.core.Symbols.newNormalizedModuleSymbolUsingClassSymbolInParents(
2778+
val mod = dotc.core.Symbols.newNormalizedModuleSymbol(
27762779
owner,
27772780
name.toTermName,
27782781
modFlags | dotc.core.Flags.ModuleValCreationFlags,
27792782
clsFlags | dotc.core.Flags.ModuleClassCreationFlags,
27802783
parents,
27812784
dotc.core.Scopes.newScope,
2782-
privateWithin)
2785+
privateWithin,
2786+
NoCoord,
2787+
compUnitInfo = null
2788+
)
27832789
val cls = mod.moduleClass.asClass
27842790
cls.enter(dotc.core.Symbols.newConstructor(cls, dotc.core.Flags.Synthetic, Nil, Nil))
27852791
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
@@ -3844,7 +3844,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
38443844
*
38453845
* Example usage:
38463846
* ```
3847-
* val name = nameExpr.valueOrAbort
3847+
* val name = "myClass"
38483848
* def decls(cls: Symbol): List[Symbol] =
38493849
* List(Symbol.newMethod(cls, "foo", MethodType(Nil)(_ => Nil, _ => TypeRepr.of[Unit])))
38503850
* val parents = List(TypeTree.of[Object])
@@ -3866,10 +3866,20 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
38663866
* Some('{println(s"Foo method call with (${${Ref(idxSym).asExpr}}, ${${Ref(strSym).asExpr}})")}.asTerm)
38673867
* )
38683868
* val clsDef = ClassDef(cls, parents, body = List(fooDef))
3869-
* val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), List(idxExpr.asTerm, strExpr.asTerm))
3869+
* val newCls = Apply(Select(New(TypeIdent(cls)), cls.primaryConstructor), List('{0}.asTerm, '{string}.asTerm))
38703870
*
38713871
* Block(List(clsDef), Apply(Select(newCls, cls.methodMember("foo")(0)), Nil)).asExprOf[Unit]
38723872
* ```
3873+
* construct the equivalent to
3874+
* ```
3875+
* '{
3876+
* class myClass(idx: Int, str: String) extends Object {
3877+
* def foo() =
3878+
* println(s"Foo method call with $idx, $str")
3879+
* }
3880+
* new myClass(0, "string").foo()
3881+
* }
3882+
* ```
38733883
* @param owner The owner of the class
38743884
* @param name The name of the class
38753885
* @param parents Function returning the parent classes of the class. The first parent must not be a trait.
@@ -3950,7 +3960,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
39503960
* constructs the equivalent to
39513961
* ```
39523962
* '{
3953-
* class myClass[T](val param: T) {
3963+
* class myClass[T](val param: T) extends Object {
39543964
* def getParam: T =
39553965
* println("Calling getParam")
39563966
* param

0 commit comments

Comments
 (0)