Skip to content

Commit 3265323

Browse files
authored
Merge pull request #1414 from dotty-staging/add-array-strawman
Add arrays to collection strawman
2 parents 5429e1d + 4e95a10 commit 3265323

14 files changed

+2602
-22
lines changed

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,14 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
648648
originalOwner
649649
}
650650
def originalOwner: Symbol = {
651+
// used to populate the EnclosingMethod attribute.
652+
// it is very tricky in presence of classes(and annonymous classes) defined inside supper calls.
651653
try {
652654
if (sym.exists) {
653655
val original = toDenot(sym).initial
654656
val validity = original.validFor
655657
val shiftedContext = ctx.withPhase(validity.phaseId)
656-
val r = toDenot(sym)(shiftedContext).maybeOwner.enclosingClass(shiftedContext)
658+
val r = toDenot(sym)(shiftedContext).maybeOwner.lexicallyEnclosingClass(shiftedContext)
657659
r
658660
} else NoSymbol
659661
} catch {

src/dotty/tools/dotc/core/Substituters.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ trait Substituters { this: Context =>
102102
}
103103
if (sym.isStatic && !existsStatic(from)) tp
104104
else {
105-
val prefix1 = substDealias(tp.prefix, from, to, theMap)
106-
if (prefix1 ne tp.prefix) tp.derivedSelect(prefix1)
107-
else if (sym.isAliasType) {
108-
val hi = sym.info.bounds.hi
109-
val hi1 = substDealias(hi, from, to, theMap)
110-
if (hi1 eq hi) tp else hi1
105+
tp.info match {
106+
case TypeAlias(alias) =>
107+
val alias1 = substDealias(alias, from, to, theMap)
108+
if (alias1 ne alias) return alias1
109+
case _ =>
111110
}
112-
else tp
111+
tp.derivedSelect(substDealias(tp.prefix, from, to, theMap))
113112
}
114113
case _: ThisType | _: BoundType | NoPrefix =>
115114
tp

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,10 @@ object SymDenotations {
844844
enclClass(symbol, false)
845845
}
846846

847+
/** A class that in source code would be lexically enclosing */
848+
final def lexicallyEnclosingClass(implicit ctx: Context): Symbol =
849+
if (!exists || isClass) symbol else owner.lexicallyEnclosingClass
850+
847851
/** A symbol is effectively final if it cannot be overridden in a subclass */
848852
final def isEffectivelyFinal(implicit ctx: Context): Boolean =
849853
is(PrivateOrFinal) || !owner.isClass || owner.is(ModuleOrFinal) || owner.isAnonymousClass

src/dotty/tools/dotc/transform/ElimByName.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
7777
if qual.tpe.derivesFrom(defn.FunctionClass(0)) && isPureExpr(qual) =>
7878
qual
7979
case _ =>
80+
val inSuper = if (ctx.mode.is(Mode.InSuperCall)) InSuperCall else EmptyFlags
8081
val meth = ctx.newSymbol(
81-
ctx.owner, nme.ANON_FUN, Synthetic | Method, MethodType(Nil, Nil, argType))
82+
ctx.owner, nme.ANON_FUN, Synthetic | Method | inSuper, MethodType(Nil, Nil, argType))
8283
Closure(meth, _ => arg.changeOwner(ctx.owner, meth))
8384
}
8485
ref(defn.dummyApply).appliedToType(argType).appliedTo(argFun)

src/dotty/tools/dotc/transform/LambdaLift.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -364,13 +364,15 @@ class LambdaLift extends MiniPhase with IdentityDenotTransformer { thisTransform
364364
if (lOwner is Package) {
365365
val encClass = local.enclosingClass
366366
val topClass = local.topLevelClass
367-
// member of a static object
368-
if (encClass.isStatic && encClass.isProperlyContainedIn(topClass)) {
369-
// though the second condition seems weird, it's not true for symbols which are defined in some
370-
// weird combinations of super calls.
371-
(encClass, EmptyFlags)
372-
} else if (encClass.is(ModuleClass, butNot = Package) && encClass.isStatic) // needed to not cause deadlocks in classloader. see t5375.scala
373-
(encClass, EmptyFlags)
367+
val preferEncClass =
368+
encClass.isStatic &&
369+
// non-static classes can capture owners, so should be avoided
370+
(encClass.isProperlyContainedIn(topClass) ||
371+
// can be false for symbols which are defined in some weird combination of supercalls.
372+
encClass.is(ModuleClass, butNot = Package)
373+
// needed to not cause deadlocks in classloader. see t5375.scala
374+
)
375+
if (preferEncClass) (encClass, EmptyFlags)
374376
else (topClass, JavaStatic)
375377
}
376378
else (lOwner, EmptyFlags)

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,13 +698,14 @@ class Namer { typer: Typer =>
698698
// the parent types are elaborated.
699699
index(constr)
700700
symbolOfTree(constr).ensureCompleted()
701+
702+
index(rest)(inClassContext(selfInfo))
701703

702704
val tparamAccessors = decls.filter(_ is TypeParamAccessor).toList
703705
val parentTypes = ensureFirstIsClass(parents.map(checkedParentType(_, tparamAccessors)))
704706
val parentRefs = ctx.normalizeToClassRefs(parentTypes, cls, decls)
705707
typr.println(s"completing $denot, parents = $parents, parentTypes = $parentTypes, parentRefs = $parentRefs")
706708

707-
index(rest)(inClassContext(selfInfo))
708709
tempInfo.finalize(denot, parentRefs)
709710

710711
Checking.checkWellFormed(cls)

src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ trait TypeAssigner {
203203
TryDynamicCallType
204204
} else {
205205
if (!site.isErroneous) {
206+
def notAMember = d"${if (name.isTypeName) "type" else "value"} $name is not a member of $site"
206207
ctx.error(
207208
if (name == nme.CONSTRUCTOR) d"$site does not have a constructor"
208-
else if (site.derivesFrom(defn.DynamicClass)) {
209-
d"$name is not a member of $site\n" +
210-
"possible cause: maybe a wrong Dynamic method signature?"
211-
} else d"$name is not a member of $site", pos)
209+
else if (site.derivesFrom(defn.DynamicClass)) s"$notAMember\npossible cause: maybe a wrong Dynamic method signature?"
210+
else notAMember,
211+
pos)
212212
}
213213
ErrorType
214214
}

0 commit comments

Comments
 (0)