File tree Expand file tree Collapse file tree 4 files changed +21
-24
lines changed
compiler/src/dotty/tools/dotc/cc
tests/neg-custom-args/captures Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -884,12 +884,11 @@ class CheckCaptures extends Recheck, SymTransformer:
884
884
val isLocal =
885
885
sym.owner.ownersIterator.exists(_.isTerm)
886
886
|| sym.accessBoundary(defn.RootClass ).isContainedIn(sym.topLevelClass)
887
- def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
888
- sym.is(Private ) // private symbols can always have inferred types
889
- || // non-local symbols cannot have inferred types since external capture types are not inferred
890
- isLocal // local symbols still need an explicit types if
891
- && ! sym.owner.is(Trait ) // - they are defined in a trait, since we do OverridingPairs checking before capture inference
892
- && ! sym.allOverriddenSymbols.nonEmpty // - they override some other symbol, since we do override checking before capture inference
887
+ def canUseInferred = // If canUseInferred is false, all capturing types in the type of `sym` need to be given explicitly
888
+ sym.is(Private ) // private symbols can always have inferred types
889
+ || // non-local symbols cannot have inferred types since external capture types are not inferred
890
+ isLocal // local symbols still need explicit types if
891
+ && ! sym.owner.is(Trait ) // they are defined in a trait, since we do OverridingPairs checking before capture inference
893
892
def isNotPureThis (ref : CaptureRef ) = ref match {
894
893
case ref : ThisType => ! ref.cls.isPureClass
895
894
case _ => true
Original file line number Diff line number Diff line change @@ -385,20 +385,18 @@ extends tpd.TreeTraverser:
385
385
return
386
386
tree.tpt match
387
387
case tpt : TypeTree if tree.symbol.allOverriddenSymbols.hasNext =>
388
+ tree.paramss.foreach(traverse)
388
389
transformTT(tpt, boxed = false , exact = true )
390
+ traverse(tree.rhs)
389
391
// println(i"TYPE of ${tree.symbol.showLocated} = ${tpt.knownType}")
390
392
case _ =>
391
- traverseChildren(tree)
393
+ traverseChildren(tree)
392
394
case tree @ ValDef (_, tpt : TypeTree , _) =>
393
- val isVar = tree.symbol.is(Mutable )
394
- val overrides = tree.symbol.allOverriddenSymbols.hasNext
395
- // if overrides then println(i"transforming overriding ${tree.symbol}")
396
- if isVar || overrides then
397
- transformTT(tpt,
398
- boxed = isVar, // types of mutable variables are boxed
399
- exact = overrides // types of symbols that override a parent don't get a capture set
400
- )
401
- traverseChildren(tree)
395
+ transformTT(tpt,
396
+ boxed = tree.symbol.is(Mutable ), // types of mutable variables are boxed
397
+ exact = tree.symbol.allOverriddenSymbols.hasNext // types of symbols that override a parent don't get a capture set
398
+ )
399
+ traverse(tree.rhs)
402
400
case tree @ TypeApply (fn, args) =>
403
401
traverse(fn)
404
402
for case arg : TypeTree <- args do
Original file line number Diff line number Diff line change 5
5
| method tail of type -> {*} lazylists.LazyList[Nothing] has incompatible type
6
6
|
7
7
| longer explanation available when compiling with `-explain`
8
+ -- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:17:15 -------------------------------------
9
+ 17 | def tail = xs() // error
10
+ | ^^^^
11
+ | Found: {LazyCons.this.xs} lazylists.LazyList[T]
12
+ | Required: lazylists.LazyList[T]
13
+ |
14
+ | longer explanation available when compiling with `-explain`
8
15
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/lazylist.scala:35:29 -------------------------------------
9
16
35 | val ref1c: LazyList[Int] = ref1 // error
10
17
| ^^^^
33
40
| Required: {cap1, ref3, cap3} lazylists.LazyList[Int]
34
41
|
35
42
| longer explanation available when compiling with `-explain`
36
- -- Error: tests/neg-custom-args/captures/lazylist.scala:17:6 -----------------------------------------------------------
37
- 17 | def tail = xs() // error: cannot have an inferred type
38
- | ^^^^^^^^^^^^^^^
39
- | Non-local method tail cannot have an inferred result type
40
- | {LazyCons.this.xs} lazylists.LazyList[? T]
41
- | with non-empty capture set {LazyCons.this.xs}.
42
- | The type needs to be declared explicitly.
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ abstract class LazyList[+T]:
14
14
class LazyCons [+ T ](val x : T , val xs : () => {* } LazyList [T ]) extends LazyList [T ]:
15
15
def isEmpty = false
16
16
def head = x
17
- def tail = xs() // error: cannot have an inferred type
17
+ def tail = xs() // error
18
18
19
19
object LazyNil extends LazyList [Nothing ]:
20
20
def isEmpty = true
You can’t perform that action at this time.
0 commit comments