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

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
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package custom
2+
3+
import scala.tools.nsc._, reporters._, typechecker._
4+
5+
/** Demonstration of a custom Global with a custom Typer,
6+
* decoupled from trunk. Demonstration:
7+
*
8+
{{{
9+
scalac -d . CustomGlobal.scala && scala -nc -Yglobal-class custom.CustomGlobal \
10+
-e 'class Bippy(x: Int) ; def f = new Bippy(5)'
11+
12+
I'm typing a Bippy! It's a ClassDef.
13+
I'm typing a Bippy! It's a Ident.
14+
I'm typing a Bippy! It's a DefDef.
15+
}}}
16+
*
17+
*/
18+
class CustomGlobal(currentSettings: Settings, reporter: Reporter) extends Global(currentSettings, reporter) {
19+
override lazy val analyzer = new {
20+
val global: CustomGlobal.this.type = CustomGlobal.this
21+
} with Analyzer {
22+
override def newTyper(context: Context): Typer = new CustomTyper(context)
23+
24+
class CustomTyper(context : Context) extends Typer(context) {
25+
override def typed(tree: Tree, mode: Mode, pt: Type): Tree = {
26+
if (tree.summaryString contains "Bippy")
27+
println("I'm typing a Bippy! It's a " + tree.shortClass + ".")
28+
29+
super.typed(tree, mode, pt)
30+
}
31+
}
32+
}
33+
}

tests/new/t296.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/pending/pos/annotations.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Needs an implementation of beanproperty to work
2+
13
class ann(i: Int) extends scala.annotation.Annotation
24
class cfann(x: String) extends annotation.ClassfileAnnotation
35

File renamed without changes.

tests/pending/pos/S5.scala renamed to tests/pos/S5.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
/* Here's a fragment of a Scala encoding for the Keris module system;
1+
/* Original comment:
2+
* Here's a fragment of a Scala encoding for the Keris module system;
23
** the compiler claims:
34
**
45
** S5.scala:28: value n in class N of type N.this._N.n
File renamed without changes.
File renamed without changes.

tests/pos/SI-7638a.scala

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Same as SI-7638, but without (Int) arguments to @specialized
2+
package miniboxing.tests.compile
3+
4+
trait Ordering[@specialized A] {
5+
def eqv(x: Array[A], y: Array[A]): Boolean = false
6+
}
7+
8+
trait ArrayVectorOrder[@specialized A] extends Ordering[A] {
9+
override def eqv(x: Array[A], y: Array[A]): Boolean = super.eqv(x, y)
10+
}
11+
12+
object vectorOrder {
13+
implicit def arrayOrder[@specialized A](): miniboxing.tests.compile.ArrayVectorOrder[A] =
14+
/*
15+
* Before applying patch:
16+
*
17+
* while compiling: SI-7638.scala
18+
* during phase: mixin
19+
* library version: version 2.10.3-20130625-164027-d22e8d282c
20+
* compiler version: version 2.10.3-20130627-153946-54cb6af7db
21+
* reconstructed args:
22+
*
23+
* last tree to typer: TypeTree(class Array)
24+
* symbol: class Array in package scala (flags: final)
25+
* symbol definition: final class Array[T >: ? <: ?] extends Object
26+
* tpe: Array[Int]
27+
* symbol owners: class Array -> package scala
28+
* context owners: anonymous class anon$1 -> package compile
29+
*
30+
* == Expanded type of tree ==
31+
*
32+
* TypeRef(
33+
* TypeSymbol(final class Array[T >: ? <: ?] extends Object)
34+
* args = List(TypeRef(TypeSymbol(final abstract class Int extends )))
35+
* )
36+
*
37+
* unhandled exception while transforming SI-7638.scala
38+
* error: uncaught exception during compilation: java.lang.UnsupportedOperationException
39+
* error: java.lang.UnsupportedOperationException: tail of empty list
40+
* at scala.collection.immutable.Nil$.tail(List.scala:339)
41+
* at scala.collection.immutable.Nil$.tail(List.scala:334)
42+
* at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:123)
43+
* at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$rebindSuper$1.apply(Mixin.scala:122)
44+
* at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:207)
45+
* at scala.reflect.internal.SymbolTable.afterPhase(SymbolTable.scala:216)
46+
* at scala.tools.nsc.Global.afterPickler(Global.scala:1104)
47+
* at scala.tools.nsc.transform.Mixin.scala$tools$nsc$transform$Mixin$$rebindSuper(Mixin.scala:122)
48+
* at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:339)
49+
* at scala.tools.nsc.transform.Mixin$$anonfun$scala$tools$nsc$transform$Mixin$$mixinTraitMembers$1$1.apply(Mixin.scala:292)
50+
*/
51+
new ArrayVectorOrder[A] { }
52+
}

tests/pos/t296.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
object Bug {
2-
def foo (l: => String) : String = 12 match { case _ => l}
2+
def foo (l: => String, l1: => String) : String = 12 match {
3+
case 12 => l1
4+
case _ => l}
35
}

tests/untried/pos/t2610.scala

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)