From b7f359c718717262fa447f428dbd600ddd3b29bd Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 22 Feb 2014 20:33:43 +0100 Subject: SI-8329 Better hygiene for patmat partial functions Don't enter synthetic parameters of `applyOrElse` et al into scope when typechecking the user-code; instead reference those symbolically. There is an exception to this principle. Currently we allow: val x: PartialFunction[A, B] = x => x match { ... } For this pattern of code, we use the given name `x` for the corresponding method parameter of `applyOrElse` and `isDefinedAt` and we actually need this to be in scope when we typecheck the scrutinee. This construct is tested in `run/virtpatmat_partial.scala`. A new parameter, `paramSynthetic`, differentiates this case from the more typical `val x: PF[A, B] = { case ... => ... ; ... } case, which uses a fresh name need not be in scope. (We could get away with it, as it is fresh, but I thought it better to exclude it.) --- test/files/pos/t8329.scala | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/files/pos/t8329.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t8329.scala b/test/files/pos/t8329.scala new file mode 100644 index 0000000000..fcd5e50b37 --- /dev/null +++ b/test/files/pos/t8329.scala @@ -0,0 +1,29 @@ +object Test { + def pf(pf: PartialFunction[Any, Unit]) = () + def f1(pf: Function[Any, Unit]) = () + + class A1; class B1 + def test1(x: String, x1: String, default: String) = pf { + case _ if ( + x.isEmpty + && default.isEmpty // was binding to synthetic param + && x1.isEmpty // was binding to synthetic param + ) => + x.isEmpty + default.isEmpty // was binding to synthetic param + x1.isEmpty // was binding to synthetic param + new A1; new B1 + } + + def test2(x: String, x1: String, default: String) = f1 { + case _ if ( + x.isEmpty + && default.isEmpty + && x1.isEmpty + ) => + x.isEmpty + default.isEmpty + x1.isEmpty + new A1; new B1 + } +} -- cgit v1.2.3