From 174334b9095be2be79c164bbdea1749dab9e0cbe Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Wed, 13 Mar 2013 19:03:53 +0100 Subject: SI-6921 SI-7239 Tread lightly during exploratory typing When deciding whether an Assign is a named argument or and assignment expression, or when looking at arguments that the current selection is applied to in order to evaluate candidate implicit views, we risk polluting the tree by setting error types. This happens even if we are in 'silent' mode; that mode does silence the error report, but not the side effect on the tree. This commit adds strategic `duplicate` calls to address the problem symptomatically. Duplicating trees and retyping in general reach into the domain of bugs umbrella-ed under SI-5464, but in these places we should be safe because the tree is in the argument position, not somewhere where, for example, a case class-es synthetic companion object might be twice entered into the same scope. Longer term, we'd like to make type checking side effect free, so we wouldn't need to play whack-a-mole like this. That idea is tracked under SI-7176. --- test/files/pos/t6921.scala | 11 +++++++++++ test/files/pos/t7239.scala | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 test/files/pos/t6921.scala create mode 100644 test/files/pos/t7239.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t6921.scala b/test/files/pos/t6921.scala new file mode 100644 index 0000000000..36e70e5d2c --- /dev/null +++ b/test/files/pos/t6921.scala @@ -0,0 +1,11 @@ +class Message(messageType: String, reason: Option[String]) + +class ReproForSI6921 { + + private[this] var reason = "" + + def decideElection = { + val explanation = None + new Message("", reason = explanation) + } +} diff --git a/test/files/pos/t7239.scala b/test/files/pos/t7239.scala new file mode 100644 index 0000000000..16e9d00f17 --- /dev/null +++ b/test/files/pos/t7239.scala @@ -0,0 +1,38 @@ +object Test { + def BrokenMethod(): HasFilter[(Int, String)] = ??? + + trait HasFilter[B] { + def filter(p: B => Boolean) = ??? + } + + trait HasWithFilter { + def withFilter = ??? + } + + object addWithFilter { + trait NoImplicit + implicit def enrich(v: Any) + (implicit F0: NoImplicit): HasWithFilter = ??? + } + + BrokenMethod().withFilter(_ => true) // okay + BrokenMethod().filter(_ => true) // okay + + locally { + import addWithFilter._ + BrokenMethod().withFilter((_: (Int, String)) => true) // okay + } + + locally { + import addWithFilter._ + // adaptToMemberWithArgs sets the type of the tree `x` + // to ErrorType (while in silent mode, so the error is not + // reported. Later, when the fallback from `withFilter` + // to `filter` is attempted, the closure is taken to have + // have the type ` => Boolean`, which conforms to + // `(B => Boolean)`. Only later during pickling does the + // defensive check for erroneous types in the tree pick up + // the problem. + BrokenMethod().withFilter(x => true) // erroneous or inaccessible type. + } +} -- cgit v1.2.3