File tree 2 files changed +25
-4
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -3808,10 +3808,25 @@ class Typer extends Namer
3808
3808
mapOver(tp)
3809
3809
}
3810
3810
3811
- if tree.symbol.isOneOf(Module | Enum )
3812
- && ! (tree.tpe frozen_<:< pt) // fast track
3813
- && ! (tree.tpe frozen_<:< approx(pt))
3814
- then
3811
+ val sym = tree.tpe.widen.classSymbol
3812
+
3813
+ // Is it certain that a value of `tree.tpe` is never a subtype of `pt`?
3814
+ // It is true if either
3815
+ // - the class of `tree.tpe` and class of `pt` cannot have common subclass, or
3816
+ // - `tree` is an object or enum value, which cannot possibly be a subtype of `pt`
3817
+ val isDefiniteNotSubtype = {
3818
+ val clsA = tree.tpe.widenDealias.classSymbol
3819
+ val clsB = pt.dealias.classSymbol
3820
+ clsA.exists && clsB.exists
3821
+ && ! clsA.isNullableClass
3822
+ && (! clsA.isNumericValueClass || ! clsB.isNumericValueClass)
3823
+ && ! clsA.asClass.mayHaveCommonChild(clsB.asClass)
3824
+ || tree.symbol.isOneOf(Module | Enum )
3825
+ && ! (tree.tpe frozen_<:< pt) // fast track
3826
+ && ! (tree.tpe frozen_<:< approx(pt))
3827
+ }
3828
+
3829
+ if isDefiniteNotSubtype then
3815
3830
// We could check whether `equals` is overriden.
3816
3831
// Reasons for not doing so:
3817
3832
// - it complicates the protocol
Original file line number Diff line number Diff line change
1
+ object UnitTest extends App {
2
+ def foo (m : Unit ) = m match {
3
+ case runtime.BoxedUnit .UNIT => println(" ok" ) // error
4
+ }
5
+ foo(())
6
+ }
You can’t perform that action at this time.
0 commit comments