Skip to content

Commit 84c43ed

Browse files
committed
Make best effort compilation work with context bound companions
If they are illegally used as values, we need to return an error tree, not a tree with a symbol that can't be pickled.
1 parent fe82424 commit 84c43ed

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,15 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
278278
}
279279
}
280280

281-
def checkUsableAsValue(tree: Tree)(using Context): Unit =
281+
def checkUsableAsValue(tree: Tree)(using Context): Tree =
282282
def unusable(msg: Symbol => Message) =
283-
report.error(msg(tree.symbol), tree.srcPos)
283+
errorTree(tree, msg(tree.symbol))
284284
if tree.symbol.is(ConstructorProxy) then
285285
unusable(ConstructorProxyNotValue(_))
286-
if tree.symbol.isContextBoundCompanion then
286+
else if tree.symbol.isContextBoundCompanion then
287287
unusable(ContextBoundCompanionNotValue(_))
288+
else
289+
tree
288290

289291
def checkStableSelection(tree: Tree)(using Context): Unit =
290292
def check(qual: Tree) =
@@ -329,20 +331,21 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
329331
if tree.isType then
330332
checkNotPackage(tree)
331333
else
332-
checkUsableAsValue(tree)
333334
registerNeedsInlining(tree)
334-
tree.tpe match {
335+
val tree1 = checkUsableAsValue(tree)
336+
tree1.tpe match {
335337
case tpe: ThisType => This(tpe.cls).withSpan(tree.span)
336-
case _ => tree
338+
case _ => tree1
337339
}
338340
case tree @ Select(qual, name) =>
339341
registerNeedsInlining(tree)
340342
if name.isTypeName then
341343
Checking.checkRealizable(qual.tpe, qual.srcPos)
342344
withMode(Mode.Type)(super.transform(checkNotPackage(tree)))
343345
else
344-
checkUsableAsValue(tree)
345-
transformSelect(tree, Nil)
346+
checkUsableAsValue(tree) match
347+
case tree1: Select => transformSelect(tree1, Nil)
348+
case tree1 => tree1
346349
case tree: Apply =>
347350
val methType = tree.fun.tpe.widen.asInstanceOf[MethodType]
348351
val app =

0 commit comments

Comments
 (0)