File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ object TyperState {
28
28
29
29
opaque type Snapshot = (Constraint , TypeVars , LevelMap )
30
30
31
+ class BadTyperStateAssertion (msg : String ) extends AssertionError (msg)
32
+
31
33
extension (ts : TyperState )
32
34
def snapshot ()(using Context ): Snapshot =
33
35
(ts.constraint, ts.ownedVars, ts.upLevels)
@@ -43,7 +45,7 @@ object TyperState {
43
45
}
44
46
45
47
class TyperState () {
46
- import TyperState .LevelMap
48
+ import TyperState .{ LevelMap , BadTyperStateAssertion }
47
49
48
50
private var myId : Int = uninitialized
49
51
def id : Int = myId
@@ -269,8 +271,10 @@ class TyperState() {
269
271
*/
270
272
private def includeVar (tvar : TypeVar )(using Context ): Unit =
271
273
val oldState = tvar.owningState.nn.get
272
- assert(oldState == null || ! oldState.isCommittable,
273
- i " $this attempted to take ownership of $tvar which is already owned by committable $oldState" )
274
+
275
+ if oldState != null && oldState.isCommittable then
276
+ throw BadTyperStateAssertion (
277
+ i " $this attempted to take ownership of $tvar which is already owned by committable $oldState" )
274
278
tvar.owningState = new WeakReference (this )
275
279
ownedVars += tvar
276
280
Original file line number Diff line number Diff line change @@ -162,6 +162,7 @@ trait Migrations:
162
162
private def checkParentheses (tree : Tree , pt : FunProto )(using Context ): Boolean =
163
163
val ptSpan = pt.args.head.span
164
164
ptSpan.exists
165
+ && tree.span.exists
165
166
&& ctx.source.content
166
167
.slice(tree.span.end, ptSpan.start)
167
168
.exists(_ == '(' )
Original file line number Diff line number Diff line change @@ -4380,11 +4380,20 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4380
4380
// But in this case we should search with additional arguments typed only if there
4381
4381
// is no default argument.
4382
4382
4383
+ // Try to constrain the result using `pt1`, but back out if a BadTyperStateAssertion
4384
+ // is thrown. TODO Find out why the bad typer state arises and prevent it. The try-catch
4385
+ // is a temporary hack to keep projects compiling that would fail otherwise due to
4386
+ // searching more arguments to instantiate implicits (PR #23532). A failing project
4387
+ // is described in issue #23609.
4388
+ def tryConstrainResult (pt : Type ): Boolean =
4389
+ try constrainResult(tree.symbol, wtp, pt)
4390
+ catch case ex : TyperState .BadTyperStateAssertion => false
4391
+
4383
4392
arg.tpe match
4384
4393
case failed : SearchFailureType if canProfitFromMoreConstraints =>
4385
4394
val pt1 = pt.deepenProtoTrans
4386
- if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && constrainResult(tree.symbol, wtp, pt1)
4387
- then return implicitArgs(formals, argIndex, pt1)
4395
+ if (pt1 `ne` pt) && (pt1 ne sharpenedPt) && tryConstrainResult( pt1) then
4396
+ return implicitArgs(formals, argIndex, pt1)
4388
4397
case _ =>
4389
4398
4390
4399
arg.tpe match
You can’t perform that action at this time.
0 commit comments