Opened 3 years ago

Closed 3 years ago

Last modified 2 years ago

#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:1 Changed 3 years ago by Feuerbach

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.

Last edited 3 years ago by Feuerbach (previous) (diff)

comment:2 in reply to:  1 Changed 3 years ago by goldfire

Component: CompilerDocumentation
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 3 years ago by goldfire

Differential Rev(s): Phab:D458
Status: newpatch

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

In ec8781f063d246a79ce1d4eb207dbee4b6317c94/ghc:

Test #9204 in roles/should_fail/T9204

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

In ee0f34d53291a7223185f83c644a25b54ea16fab/ghc:

Fix #9204 by outputting extra info on boot file mismatch.

[skip ci] -- testsuite wibbles are in next commit

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

In 90a2bb6fc66e9341ae466ff3ff6c9da438e159c2/ghc:

Testsuite wibbles due to #9204

comment:7 Changed 3 years ago by goldfire

Resolution: fixed
Status: patchclosed
Test Case: roles/should_fail/T9204

comment:8 Changed 3 years ago by phischu

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 3 years ago by goldfire

Milestone: 7.12.1
Owner: goldfire deleted
Priority: normallow
Resolution: fixed
Status: closednew

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 3 years ago by goldfire

Owner: set to goldfire

comment:11 Changed 3 years ago by simonpj

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:12 Changed 3 years ago by Richard Eisenberg <eir@…>

In 72a927267d9c658a2e5d226a855702d348472516/ghc:

Change default roles in hs-boot files. (#9204)

Test case: roles/should_compile/T9204b

comment:13 Changed 3 years ago by goldfire

Resolution: fixed
Status: newclosed
Test Case: roles/should_fail/T9204roles/should_fail/T9204 roles/should_compile/T9204b

This is a user-facing change, so wait until 7.12.

comment:14 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.