From cd8bf2d69cf1463fa16a69badb2a839f540bb2fa Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 6 May 2016 12:30:55 +0200 Subject: Hooks to check that comparisons with == / != make sense Also, check that pattern matching against idents/selects/literals makes sense. The hooks perform an implicit search for an instance of `Eq[L, R]`, where `L`, `R` are the argument types. So far this always succeeeds because Eq.eqAny matches all such types. A separate commit will check the returned search term for validity. --- src/dotty/tools/dotc/typer/Applications.scala | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/typer/Applications.scala') diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 6ce98606b..2b0cc4033 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -603,7 +603,17 @@ trait Applications extends Compatibility { self: Typer => failedVal } } - else realApply + else { + val app = realApply + app match { + case Apply(fn @ Select(left, _), right :: Nil) if fn.hasType => + val op = fn.symbol + if (op == defn.Any_== || op == defn.Any_!=) + checkCanEqual(left.tpe.widen, right.tpe.widen, app.pos) + case _ => + } + app + } } /** Overridden in ReTyper to handle primitive operations that can be generated after erasure */ -- cgit v1.2.3