Skip to content

Commit fd072dc

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 9d0ca20 commit fd072dc

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
@@ -279,13 +279,15 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
279279
}
280280
}
281281

282-
def checkUsableAsValue(tree: Tree)(using Context): Unit =
282+
def checkUsableAsValue(tree: Tree)(using Context): Tree =
283283
def unusable(msg: Symbol => Message) =
284-
report.error(msg(tree.symbol), tree.srcPos)
284+
errorTree(tree, msg(tree.symbol))
285285
if tree.symbol.is(ConstructorProxy) then
286286
unusable(ConstructorProxyNotValue(_))
287-
if tree.symbol.isContextBoundCompanion then
287+
else if tree.symbol.isContextBoundCompanion then
288288
unusable(ContextBoundCompanionNotValue(_))
289+
else
290+
tree
289291

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

0 commit comments

Comments
 (0)