Skip to content

Commit fdb6fc7

Browse files
committed
Move Winfer-union to MiniPhase
1 parent 48d50b0 commit fdb6fc7

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Compiler {
3434
List(new Parser) :: // Compiler frontend: scanner, parser
3535
List(new TyperPhase) :: // Compiler frontend: namer, typer
3636
List(CheckUnused.PostTyper(), CheckShadowing()) :: // Check for unused, shadowed elements
37+
List(new WInferUnion) :: // Winfer-union
3738
List(new YCheckPositions) :: // YCheck positions
3839
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
3940
List(new semanticdb.ExtractSemanticDB.ExtractSemanticInfo) :: // Extract info into .semanticdb files

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -534,14 +534,6 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
534534
if (fn.symbol != defn.ChildAnnot.primaryConstructor)
535535
// Make an exception for ChildAnnot, which should really have AnyKind bounds
536536
Checking.checkBounds(args, fn.tpe.widen.asInstanceOf[PolyType])
537-
if ctx.settings.Whas.inferUnion then
538-
val inferredOrTypes = args.find: tpt =>
539-
tpt.isInstanceOf[InferredTypeTree] && tpt.tpe.stripTypeVar.isInstanceOf[OrType]
540-
inferredOrTypes.foreach: tpt =>
541-
report.warning(
542-
em"""|A type argument was inferred to be union type ${tpt.tpe.stripTypeVar}
543-
|This may indicate a programming error.
544-
|""", tpt.srcPos)
545537
fn match {
546538
case sel: Select =>
547539
val args1 = transform(args)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package dotty.tools.dotc.transform
2+
3+
import dotty.tools.dotc.ast.tpd
4+
import dotty.tools.dotc.ast.tpd.InferredTypeTree
5+
import dotty.tools.dotc.core.Contexts.{Context, ctx}
6+
import dotty.tools.dotc.core.Decorators.em
7+
import dotty.tools.dotc.core.Types.OrType
8+
import dotty.tools.dotc.report
9+
import dotty.tools.dotc.transform.MegaPhase.MiniPhase
10+
11+
class WInferUnion extends MiniPhase {
12+
13+
override def phaseName: String = WInferUnion.name
14+
15+
override def description: String = WInferUnion.description
16+
17+
override def isEnabled(using Context): Boolean = ctx.settings.Whas.inferUnion
18+
19+
override def transformTypeApply(tree: tpd.TypeApply)(using Context): tpd.Tree =
20+
val inferredOrTypes = tree.args.find: tpt =>
21+
tpt.isInstanceOf[InferredTypeTree] && tpt.tpe.stripTypeVar.isInstanceOf[OrType]
22+
inferredOrTypes.foreach: tpt =>
23+
report.warning(
24+
em"""|A type argument was inferred to be union type ${tpt.tpe.stripTypeVar}
25+
|This may indicate a programming error.
26+
|""", tpt.srcPos)
27+
tree
28+
}
29+
30+
object WInferUnion:
31+
val name = "Winfer-union"
32+
val description = "warn if type argument inferred as union type"

0 commit comments

Comments
 (0)