summaryrefslogtreecommitdiff
path: root/testsuite/tests/th/T2713.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2019-07-12 10:47:05 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-07-26 00:57:02 -0400
commit30b6f391801d58e364f79df5da2cf9f02be2ba5f (patch)
treef11e81851c126fa689c60f157ec768bebe1fe35b /testsuite/tests/th/T2713.hs
parentb9c99df1a4cdd23bcd26db7ae6ee7ee6464d654e (diff)
downloadhaskell-30b6f391801d58e364f79df5da2cf9f02be2ba5f.tar.gz
Banish reportFloatingViaTvs to the shadow realm (#15831, #16181)
GHC used to reject programs of this form: ``` newtype Age = MkAge Int deriving Eq via Const Int a ``` That's because an earlier implementation of `DerivingVia` would generate the following instance: ``` instance Eq Age where (==) = coerce @(Const Int a -> Const Int a -> Bool) @(Age -> Age -> Bool) (==) ``` Note that the `a` in `Const Int a` is not bound anywhere, which causes all sorts of issues. I figured that no one would ever want to write code like this anyway, so I simply banned "floating" `via` type variables like `a`, checking for their presence in the aptly named `reportFloatingViaTvs` function. `reportFloatingViaTvs` ended up being implemented in a subtly incorrect way, as #15831 demonstrates. Following counsel with the sage of gold fire, I decided to abandon `reportFloatingViaTvs` entirely and opt for a different approach that would _accept_ the instance above. This is because GHC now generates this instance instead: ``` instance forall a. Eq Age where (==) = coerce @(Const Int a -> Const Int a -> Bool) @(Age -> Age -> Bool) (==) ``` Notice that we now explicitly quantify the `a` in `instance forall a. Eq Age`, so everything is peachy scoping-wise. See `Note [Floating `via` type variables]` in `TcDeriv` for the full scoop. A pleasant benefit of this refactoring is that it made it much easier to catch the problem observed in #16181, so this patch fixes that issue too. Fixes #15831. Fixes #16181.
Diffstat (limited to 'testsuite/tests/th/T2713.hs')
0 files changed, 0 insertions, 0 deletions