#9204 closed bug (fixed)
Conflicting definition in hs-boot file
Reported by: | Feuerbach | Owned by: | goldfire |
---|---|---|---|
Priority: | low | Milestone: | 8.0.1 |
Component: | Documentation | Version: | 7.8.2 |
Keywords: | Cc: | ||
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | None/Unknown | Test Case: | roles/should_fail/T9204 roles/should_compile/T9204b |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | Phab:D458 | |
Wiki Page: |
Description
Foo.hs:
module Foo where import Bar data Foo a
Foo.hs-boot:
module Foo where data Foo a
Bar.hs:
module Bar where import {-# SOURCE #-} Foo
With GHC 7.8.2 I'm getting the error
Foo.hs-boot:3:1: Type constructor ‘Foo’ has conflicting definitions in the module and its hs-boot file Main module: type role Foo phantom data Foo a Boot file: data Foo a
Change History (14)
comment:2 Changed 6 years ago by
Component: | Compiler → Documentation |
---|---|
Owner: | set to goldfire |
Replying to Feuerbach:
If I add a role annotation to the hs-boot file, this works
Yes, that's the solution. .
My guess is that since the hs-boot doesn't have the information about the data constructors, it cannot infer the phantom role of the parameter.
Yes. As documented here, in the last bullet point before 4.7.10, role inference in hs-boot files defaults to representational, the most common case.
Still, I wish I didn't have to deal with this. But if this isn't possible, at least the error message should suggest adding the role annotation to the hs-boot file.
Yes, absolutely. I will fix in due course, and clarify some of this in the manual as well.
comment:3 Changed 5 years ago by
Differential Rev(s): | → Phab:D458 |
---|---|
Status: | new → patch |
comment:7 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | patch → closed |
Test Case: | → roles/should_fail/T9204 |
comment:8 Changed 5 years ago by
In the following example the complete data declaration happens to be present in the hs-boot file:
Foo.hs:
module Foo where import Bar data P a = P
Foo.hs-boot:
module Foo where data P a = P
Bar.hs:
module Bar where import {-# SOURCE #-} Foo
Could you now do role inference in the hs-boot file as well, so that the example compiles? My use-case is that I generate hs-boot files by copying whole declarations. Thank you.
comment:9 Changed 5 years ago by
Milestone: | → 7.12.1 |
---|---|
Owner: | goldfire deleted |
Priority: | normal → low |
Resolution: | fixed |
Status: | closed → new |
Yes, the suggestion in comment:8 is reasonable: Use phantom
as the default role in hs-boot files when the definition is supplied. Even today, GHC does do role inference in hs-boot files -- it just uses a different default. But there is no reason to change the default if a definition is supplied.
Thanks for the suggestion.
However, because this is a user-facing change, it's not appropriate (in my opinion) to make the change for 7.10. And, it's just barely possible that this will break code. The following compiles today:
A.hs-boot:
module A where data P a = P
A.hs:
module A where type role P representational data P a = P
Under the proposed change, this example would fail due to the missing role annotation in the hs-boot file. That said, I'm still in favor of the change, just documenting what would break.
comment:10 Changed 5 years ago by
Owner: | set to goldfire |
---|
comment:11 Changed 5 years ago by
OK let's change this for 7.12, and document the change. Richard, you took ownership, so maybe do this whenever it's convenient to you.
Simon
comment:13 Changed 5 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Test Case: | roles/should_fail/T9204 → roles/should_fail/T9204 roles/should_compile/T9204b |
This is a user-facing change, so wait until 7.12.
If I add a role annotation to the hs-boot file, this works.
My guess is that since the hs-boot doesn't have the information about the data constructors, it cannot infer the phantom role of the parameter.
Still, I wish I didn't have to deal with this. But if this isn't possible, at least the error message should suggest adding the role annotation to the hs-boot file.