File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,22 @@ object CheckLoopingImplicits:
1212 val name : String = " checkLoopingImplicits"
1313 val description : String = " check that implicit defs do not call themselves in an infinite loop"
1414
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+ */
1631class CheckLoopingImplicits extends MiniPhase :
1732 thisPhase =>
1833 import tpd ._
Original file line number Diff line number Diff line change 11import scala .language .implicitConversions
22
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.
59
610object Prices {
711 opaque type Price = BigDecimal
You can’t perform that action at this time.
0 commit comments