File tree Expand file tree Collapse file tree 4 files changed +24
-16
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ object Mode {
41
41
*/
42
42
val TypevarsMissContext : Mode = newMode(4 , " TypevarsMissContext" )
43
43
44
+ /** Are we looking for cyclic references? */
44
45
val CheckCyclic : Mode = newMode(5 , " CheckCyclic" )
45
46
46
47
/** We are in a pattern alternative */
Original file line number Diff line number Diff line change @@ -2710,7 +2710,7 @@ object Types {
2710
2710
}
2711
2711
}
2712
2712
2713
- case class LazyRef (private var refFn : Context ?=> Type , reportCycles : Boolean = false ) extends UncachedProxyType with ValueType {
2713
+ case class LazyRef (private var refFn : Context ?=> Type ) extends UncachedProxyType with ValueType {
2714
2714
private var myRef : Type = null
2715
2715
private var computed = false
2716
2716
@@ -2719,7 +2719,7 @@ object Types {
2719
2719
if myRef == null then
2720
2720
// if errors were reported previously handle this by throwing a CyclicReference
2721
2721
// instead of crashing immediately. A test case is neg/i6057.scala.
2722
- assert(reportCycles || ctx.reporter.errorsReported)
2722
+ assert(ctx.mode.is( Mode . CheckCyclic ) || ctx.reporter.errorsReported)
2723
2723
throw CyclicReference (NoDenotation )
2724
2724
else
2725
2725
computed = true
@@ -4545,7 +4545,9 @@ object Types {
4545
4545
else defn.AnyType // dummy type in case of errors
4546
4546
def refineSelfType (selfType : Type ) =
4547
4547
RefinedType (selfType, sym.name,
4548
- TypeAlias (LazyRef (force, reportCycles = true )))
4548
+ TypeAlias (
4549
+ withMode(Mode .CheckCyclic )(
4550
+ LazyRef (force))))
4549
4551
cinfo.selfInfo match
4550
4552
case self : Type =>
4551
4553
cinfo.derivedClassInfo(
Original file line number Diff line number Diff line change @@ -406,21 +406,19 @@ object Checking {
406
406
for (parent <- parents; mbr <- parent.abstractTypeMembers if qualifies(mbr.symbol))
407
407
yield mbr.name.asTypeName
408
408
409
- for (name <- abstractTypeNames)
410
- try {
411
- val mbr = joint.member(name)
412
- mbr.info match {
413
- case bounds : TypeBounds =>
414
- ! checkNonCyclic(mbr.symbol, bounds, reportErrors = true ).isError
415
- case _ =>
416
- true
417
- }
418
- }
419
- catch {
420
- case ex : RecursionOverflow =>
409
+ withMode(Mode .CheckCyclic ) {
410
+ for name <- abstractTypeNames do
411
+ try
412
+ val mbr = joint.member(name)
413
+ mbr.info match
414
+ case bounds : TypeBounds =>
415
+ ! checkNonCyclic(mbr.symbol, bounds, reportErrors = true ).isError
416
+ case _ =>
417
+ true
418
+ catch case _ : RecursionOverflow | _ : CyclicReference =>
421
419
report.error(em " cyclic reference involving type $name" , pos)
422
420
false
423
- }
421
+ }
424
422
}
425
423
426
424
/** Check that symbol's definition is well-formed. */
Original file line number Diff line number Diff line change
1
+ trait Foo [T <: Foo [T ]] {
2
+ type I <: Foo [I ]
3
+ }
4
+
5
+ trait Bar [T <: Foo [T ]] extends Foo [T ] { // error: cyclic
6
+ self : T =>
7
+ }
You can’t perform that action at this time.
0 commit comments