Opened 3 years ago

Closed 3 years ago

#8773 closed bug (fixed)

Require -XIncoherentInstances to write role annotations on class definitions

Reported by: goldfire Owned by: goldfire
Priority: normal Milestone: 7.8.1
Component: Compiler Version: 7.8.1-rc1
Keywords: Cc: mail@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: roles/should_fail/T8773
Blocked By: Blocking:
Related Tickets: #8745 Differential Rev(s):
Wiki Page:


With a role annotation declaring a representational role for a class parameter, it is very easy to create instance incoherence. See this comment. The solution: require -XIncoherentInstances when writing such a role annotation. This also has the knock-on effect (happily) of preventing such shenanigans in Safe Haskell.

Class role annotations asking GHC to infer roles or with nominal roles, although rather useless, will still be accepted without -XIncoherentInstances.

Change History (9)

comment:1 Changed 3 years ago by nomeata

Cc: mail@… added

comment:2 Changed 3 years ago by thoughtpolice

Milestone: 7.8.1

comment:3 Changed 3 years ago by thoughtpolice

Blocking: 8745 added

comment:4 Changed 3 years ago by Richard Eisenberg <eir@…>

In 138297585f88351352e0ed878b25f26e1d6edfef/ghc:

Fix #8773.

To make a role annotation on a class asserting a role other than
nominal, you now need -XIncoherentInstances. See the ticket for
more information as to why this is a good idea.

comment:5 Changed 3 years ago by goldfire

Status: newmerge
Test Case: roles/should_fail/T8773

I think (once again) that GND and coerce are Safe.

comment:6 Changed 3 years ago by goldfire

Blocking: 8745 removed

comment:7 Changed 3 years ago by Austin Seipp <austin@…>

In a8a01e742434df11b830ab99af12d9045dfcbc4b/ghc:

Fix #8745 - GND is now -XSafe compatible.

As discussed in the ticket, after the landing of #8773, GND is now
-XSafe compatible.

This fixes the test fallout as well. In particular SafeLang07 was
removed following in the steps of SafeLang06, since it no longer failed
from GND, but failed due to roles and was thus invalid.

The other tests were tweaked to use TemplateHaskell instead of GND in
order to trigger safety warnings.

Signed-off-by: Austin Seipp <>

comment:8 Changed 3 years ago by thoughtpolice

Merged in 7.8.

comment:9 Changed 3 years ago by thoughtpolice

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.