From fe57a5bae3f8cb87637359f615c77f4afae86d46 Mon Sep 17 00:00:00 2001 From: Matthew Yacavone Date: Thu, 29 Nov 2018 18:42:39 -0500 Subject: Fix #15828, from `More explicit foralls` Summary: Fix a bug in commit 12eeb9 which permits the following: ``` class C a where type T a b instance C (Maybe a) where type forall a b. T (Maybe a) b = b ``` where instead, the user should write: ``` instance C (Maybe a) where type forall b. T (Maybe a) b = b ``` Update the users guide to discuss scoping of type variables in explicit foralls in type family instances. Test Plan: validate Reviewers: bgamari, goldfire, monoidal Reviewed By: goldfire Subscribers: monoidal, rwbarton, carter GHC Trac Issues: #15828 Differential Revision: https://phabricator.haskell.org/D5283 --- testsuite/tests/rename/should_fail/T15828.hs | 9 +++++++++ testsuite/tests/rename/should_fail/T15828.stderr | 9 +++++++++ testsuite/tests/rename/should_fail/all.T | 1 + 3 files changed, 19 insertions(+) create mode 100644 testsuite/tests/rename/should_fail/T15828.hs create mode 100644 testsuite/tests/rename/should_fail/T15828.stderr (limited to 'testsuite/tests/rename/should_fail') diff --git a/testsuite/tests/rename/should_fail/T15828.hs b/testsuite/tests/rename/should_fail/T15828.hs new file mode 100644 index 0000000000..90c06214c4 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T15828.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE TypeFamilies, ExplicitForAll #-} + +module T15828 where + +class C a where + type T a b + +instance C (Maybe a) where + type forall a b. T (Maybe a) b = b diff --git a/testsuite/tests/rename/should_fail/T15828.stderr b/testsuite/tests/rename/should_fail/T15828.stderr new file mode 100644 index 0000000000..aca2542d88 --- /dev/null +++ b/testsuite/tests/rename/should_fail/T15828.stderr @@ -0,0 +1,9 @@ + +T15828.hs:9:20: error: + • Type indexes must match class instance head + Expected: T (Maybe a1) + Actual: T (Maybe a) b + where the `' arguments are type variables, + distinct from each other and from the instance variables + • In the type instance declaration for ‘T’ + In the instance declaration for ‘C (Maybe a)’ \ No newline at end of file diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T index 9ca330f873..6fd014356c 100644 --- a/testsuite/tests/rename/should_fail/all.T +++ b/testsuite/tests/rename/should_fail/all.T @@ -140,5 +140,6 @@ test('T15659', normal, compile_fail, ['']) test('T15607', normal, compile_fail, ['']) test('T15611a', normal, compile_fail, ['']) test('T15611b', normal, ghci_script, ['T15611b.script']) +test('T15828', normal, compile_fail, ['']) test('ExplicitForAllRules2', normal, compile_fail, ['']) -- cgit v1.2.1