Skip to content

Commit dbeceba

Browse files
committed
Merge pull request #313 from dotty-staging/more-tests
More tests
2 parents 5acaad6 + b6755f6 commit dbeceba

File tree

28 files changed

+147
-58
lines changed

28 files changed

+147
-58
lines changed

src/dotty/tools/dotc/TypeErasure.scala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ object TypeErasure {
160160
* as upper bound and that is not Java defined? Arrays of such types are
161161
* erased to `Object` instead of `ObjectArray`.
162162
*/
163-
def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp match {
163+
def isUnboundedGeneric(tp: Type)(implicit ctx: Context): Boolean = tp.dealias match {
164164
case tp: TypeRef =>
165-
tp.symbol.isAbstractType &&
165+
!tp.symbol.isClass &&
166166
!tp.derivesFrom(defn.ObjectClass) &&
167-
!tp.typeSymbol.is(JavaDefined)
167+
!tp.symbol.is(JavaDefined)
168168
case tp: PolyParam =>
169169
!tp.derivesFrom(defn.ObjectClass) &&
170170
!tp.binder.resultType.isInstanceOf[JavaMethodType]
@@ -342,11 +342,7 @@ class TypeErasure(isJava: Boolean, isSemi: Boolean, isConstructor: Boolean, wild
342342
private def eraseArray(tp: RefinedType)(implicit ctx: Context) = {
343343
val defn.ArrayType(elemtp) = tp
344344
if (elemtp derivesFrom defn.NullClass) JavaArrayType(defn.ObjectType)
345-
else if (isUnboundedGeneric(elemtp))
346-
elemtp match {
347-
case elemtp: TypeRef if elemtp.symbol.is(JavaDefined) => JavaArrayType(defn.ObjectType)
348-
case _ => defn.ObjectType
349-
}
345+
else if (isUnboundedGeneric(elemtp)) defn.ObjectType
350346
else JavaArrayType(this(elemtp))
351347
}
352348

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,12 @@ object desugar {
290290
val caseParams = constrVparamss.head.toArray
291291
val productElemMeths = for (i <- 0 until arity) yield
292292
syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeName), caseParams(i).name))
293+
val hasRepeatedParam = constrVparamss.exists(_.exists {
294+
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) => true
295+
case _ => false
296+
})
293297
val copyMeths =
294-
if (mods is Abstract) Nil
298+
if (mods.is(Abstract) || hasRepeatedParam) Nil // cannot have default arguments for repeated parameters, hence copy method is not issued
295299
else {
296300
def copyDefault(vparam: ValDef) =
297301
makeAnnotated(defn.UncheckedVarianceAnnot, refOfDef(vparam))

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ object Contexts {
170170
if (implicitsCache == null )
171171
implicitsCache = {
172172
val implicitRefs: List[TermRef] =
173-
if (isClassDefContext) owner.thisType.implicitMembers
173+
if (isClassDefContext)
174+
try owner.thisType.implicitMembers
175+
catch {
176+
case ex: CyclicReference => Nil
177+
}
174178
else if (isImportContext) importInfo.importedImplicits
175179
else if (isNonEmptyScopeContext) scope.implicitDecls
176180
else Nil

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ object NameOps {
7272
def isSetterName = name endsWith SETTER_SUFFIX
7373
def isSingletonName = name endsWith SINGLETON_SUFFIX
7474
def isModuleClassName = name endsWith MODULE_SUFFIX
75+
def isAvoidClashName = name endsWith AVOID_CLASH_SUFFIX
7576
def isImportName = name startsWith IMPORT
7677
def isFieldName = name endsWith LOCAL_SUFFIX
7778
def isInheritedName = name.length > 0 && name.head == '(' && name.startsWith(nme.INHERITED)
@@ -129,11 +130,19 @@ object NameOps {
129130
/** If name ends in module class suffix, drop it */
130131
def stripModuleClassSuffix: Name =
131132
if (isModuleClassName) name dropRight MODULE_SUFFIX.length else name
133+
134+
/** Append a suffix so that this name does not clash with another name in the same scope */
135+
def avoidClashName: TermName = (name ++ AVOID_CLASH_SUFFIX).toTermName
136+
137+
/** If name ends in "avoid clash" suffix, drop it */
138+
def stripAvoidClashSuffix: Name =
139+
if (isAvoidClashName) name dropRight AVOID_CLASH_SUFFIX.length else name
132140

133141
/** If flags is a ModuleClass but not a Package, add module class suffix */
134-
def adjustIfModuleClass(flags: Flags.FlagSet): N =
135-
if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName.asInstanceOf[N]
136-
else name
142+
def adjustIfModuleClass(flags: Flags.FlagSet): N = {
143+
if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName
144+
else stripAvoidClashSuffix
145+
}.asInstanceOf[N]
137146

138147
/** The superaccessor for method with given name */
139148
def superName: TermName = (nme.SUPER_PREFIX ++ name).toTermName

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ object StdNames {
107107
val INTERPRETER_WRAPPER_SUFFIX: N = "$object"
108108
val LOCALDUMMY_PREFIX: N = "<local " // owner of local blocks
109109
val MODULE_SUFFIX: N = NameTransformer.MODULE_SUFFIX_STRING
110+
val AVOID_CLASH_SUFFIX: N = "$_avoid_name_clash_$"
110111
val MODULE_VAR_SUFFIX: N = "$module"
111112
val NAME_JOIN: N = NameTransformer.NAME_JOIN_STRING
112113
val USCORE_PARAM_PREFIX: N = "_$"

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ object SymDenotations {
171171
myInfo = tp
172172
}
173173

174-
/** The name, except if this is a module class, strip the module class suffix */
174+
/** The name, except
175+
* - if this is a module class, strip the module class suffix
176+
* - if this is a companion object with a clash-avoiding name, strip the
177+
* "avoid clash" suffix
178+
*/
175179
def effectiveName(implicit ctx: Context) =
176-
if (this is ModuleClass) name.stripModuleClassSuffix else name
180+
if (this is ModuleClass) name.stripModuleClassSuffix
181+
else name.stripAvoidClashSuffix
177182

178183
/** The privateWithin boundary, NoSymbol if no boundary is given.
179184
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,7 @@ object Types {
29762976
val ex = new CyclicReference(denot)
29772977
if (!(ctx.mode is typer.Mode.CheckCyclic)) {
29782978
cyclicErrors.println(ex.getMessage)
2979-
for (elem <- ex.getStackTrace take 40)
2979+
for (elem <- ex.getStackTrace take 50)
29802980
cyclicErrors.println(elem.toString)
29812981
}
29822982
ex

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,15 @@ class FirstTransform extends MiniPhaseTransform with IdentityDenotTransformer wi
8181

8282
def addMissingCompanions(stats: List[Tree]): List[Tree] = stats map {
8383
case stat: TypeDef if singleClassDefs contains stat.name =>
84-
Thicket(stat :: newCompanion(stat.name.toTermName).trees)
84+
val objName = stat.name.toTermName
85+
val nameClash = stats.exists {
86+
case other: MemberDef =>
87+
other.name == objName && other.symbol.info.isParameterless
88+
case _ =>
89+
false
90+
}
91+
val uniqueName = if (nameClash) objName.avoidClashName else objName
92+
Thicket(stat :: newCompanion(uniqueName).trees)
8593
case stat => stat
8694
}
8795

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,15 @@ class Namer { typer: Typer =>
674674

675675
def typeDefSig(tdef: TypeDef, sym: Symbol)(implicit ctx: Context): Type = {
676676
completeParams(tdef.tparams)
677-
sym.info = TypeBounds.empty
677+
val tparamSyms = tdef.tparams map symbolOfTree
678+
val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
679+
val toParameterize = tparamSyms.nonEmpty && !isDerived
680+
val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived
681+
def abstracted(tp: Type): Type =
682+
if (needsLambda) tp.LambdaAbstract(tparamSyms)
683+
else if (toParameterize) tp.parameterizeWith(tparamSyms)
684+
else tp
685+
sym.info = abstracted(TypeBounds.empty)
678686
// Temporarily set info of defined type T to ` >: Nothing <: Any.
679687
// This is done to avoid cyclic reference errors for F-bounds.
680688
// This is subtle: `sym` has now an empty TypeBounds, but is not automatically
@@ -685,18 +693,10 @@ class Namer { typer: Typer =>
685693
//
686694
// The scheme critically relies on an implementation detail of isRef, which
687695
// inspects a TypeRef's info, instead of simply dealiasing alias types.
688-
val tparamSyms = tdef.tparams map symbolOfTree
689-
val isDerived = tdef.rhs.isInstanceOf[untpd.DerivedTypeTree]
690-
val toParameterize = tparamSyms.nonEmpty && !isDerived
691-
val needsLambda = sym.allOverriddenSymbols.exists(_ is HigherKinded) && !isDerived
692696
val rhsType = typedAheadType(tdef.rhs).tpe
693-
def abstractedRhsType =
694-
if (needsLambda) rhsType.LambdaAbstract(tparamSyms)
695-
else if (toParameterize) rhsType.parameterizeWith(tparamSyms)
696-
else rhsType
697697
val unsafeInfo = rhsType match {
698-
case _: TypeBounds => abstractedRhsType.asInstanceOf[TypeBounds]
699-
case _ => TypeAlias(abstractedRhsType, if (sym is Local) sym.variance else 0)
698+
case _: TypeBounds => abstracted(rhsType).asInstanceOf[TypeBounds]
699+
case _ => TypeAlias(abstracted(rhsType), if (sym is Local) sym.variance else 0)
700700
}
701701
sym.info = NoCompleter
702702
checkNonCyclic(sym, unsafeInfo, reportErrors = true)

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,6 @@ object RefChecks {
184184
emitOverrideError(overrideErrorMsg(msg))
185185
}
186186

187-
def overrideTypeError() = {
188-
if (noErrorType) {
189-
emitOverrideError(overrideErrorMsg("has incompatible type"))
190-
}
191-
}
192-
193187
def overrideAccessError() = {
194188
ctx.log(i"member: ${member.showLocated} ${member.flags}") // DEBUG
195189
ctx.log(i"other: ${other.showLocated} ${other.flags}") // DEBUG

0 commit comments

Comments
 (0)