File tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings
2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,22 @@ object CheckLoopingImplicits:
12
12
val name : String = " checkLoopingImplicits"
13
13
val description : String = " check that implicit defs do not call themselves in an infinite loop"
14
14
15
- /** Checks that implicit defs do not call themselves in an infinite loop */
15
+ /** Checks that some definitions do not call themselves in an infinite loop
16
+ * This is an incomplete check, designed to catch some likely bugs instead
17
+ * of being exhaustive. The situations where infinite loops are diagnosed are
18
+ * 1. A given method should not directly call itself
19
+ * 2. An apply method in a given object should not directly call itself
20
+ * 3. A lazy val should not directly force itself
21
+ * 4. An extension method should not directly call itself
22
+ *
23
+ * In all these cases, there are some situations which would not lead to
24
+ * an infinite loop at runtime. For instance, the call could go at runtime to an
25
+ * overriding version of the method or val which breaks the loop. That's why
26
+ * this phase only issues warnings, not errors, and also why we restrict
27
+ * checks to the 4 cases above, where a recursion is somewhat hidden.
28
+ * There are also other more complicated calling patterns that could also
29
+ * be diagnosed as loops with more effort. This could be improved in the future.
30
+ */
16
31
class CheckLoopingImplicits extends MiniPhase :
17
32
thisPhase =>
18
33
import tpd ._
Original file line number Diff line number Diff line change 1
1
import scala .language .implicitConversions
2
2
3
- given Conversion [ String , Int ] with
4
- def apply (from : String ): Int = from.toInt // error
3
+ object Test1 :
4
+ given c : Conversion [ String , Int ] with
5
+ def apply (from : String ): Int = from.toInt // error
6
+
7
+ object Test2 :
8
+ given c : Conversion [ String , Int ] = _.toInt // loop not detected, could be used as a fallback to avoid the warning.
5
9
6
10
object Prices {
7
11
opaque type Price = BigDecimal
You can’t perform that action at this time.
0 commit comments