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 @@ -2680,7 +2680,7 @@ object Types {
2680
2680
}
2681
2681
}
2682
2682
2683
- case class LazyRef (private var refFn : Context ?=> Type , reportCycles : Boolean = false ) extends UncachedProxyType with ValueType {
2683
+ case class LazyRef (private var refFn : Context ?=> Type ) extends UncachedProxyType with ValueType {
2684
2684
private var myRef : Type = null
2685
2685
private var computed = false
2686
2686
@@ -2689,7 +2689,7 @@ object Types {
2689
2689
if myRef == null then
2690
2690
// if errors were reported previously handle this by throwing a CyclicReference
2691
2691
// instead of crashing immediately. A test case is neg/i6057.scala.
2692
- assert(reportCycles || ctx.reporter.errorsReported)
2692
+ assert(ctx.mode.is( Mode . CheckCyclic ) || ctx.reporter.errorsReported)
2693
2693
throw CyclicReference (NoDenotation )
2694
2694
else
2695
2695
computed = true
@@ -4515,7 +4515,9 @@ object Types {
4515
4515
else defn.AnyType // dummy type in case of errors
4516
4516
def refineSelfType (selfType : Type ) =
4517
4517
RefinedType (selfType, sym.name,
4518
- TypeAlias (LazyRef (force, reportCycles = true )))
4518
+ TypeAlias (
4519
+ withMode(Mode .CheckCyclic )(
4520
+ LazyRef (force))))
4519
4521
cinfo.selfInfo match
4520
4522
case self : Type =>
4521
4523
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