Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modules are permitted to re-export a type class and a type of the same name #3502

Closed
hdgarrood opened this issue Jan 6, 2019 · 3 comments
Closed

Comments

@hdgarrood
Copy link
Contributor

Currently, it's possible to re-export a type and a type class of the same name from a module, even though it's not possible to define a type and a type class of the same name together in one module. For example,

-- Eg.Type.purs
module Eg.Type where

data X = X

-- Eg.Class.purs
module Eg.Class where

class X a

-- Eg.purs
module Eg (module Type, module Class) where

import Eg.Type (X)
import Eg.Class (class X)

There is an example of this in purescript-typelevel-prelude at version 3.0.0, where the module Type.Row re-exports the class Cons from Prim.Row as well as the type Cons from Prim.RowList. At the moment, this is only a minor issue; as far as I'm aware, the only problem this can cause is that it can break anchor links in docs. However, if we ever want to do #1888 (which do still I think we should), I think we will need to make this an error.

@hdgarrood
Copy link
Contributor Author

Presumably then the plan is to fix this by disallowing it? That will be a breaking change, so shall we label it breaking?

@garyb
Copy link
Member

garyb commented Jan 7, 2019

Sure thing

@hdgarrood hdgarrood added this to the 0.13.0 milestone Feb 24, 2019
joneshf added a commit to joneshf/purescript that referenced this issue May 26, 2019
Within a module,
we cannot define a class and a data type with the same name.
The issue here is that we can define a class and a data type with
the same name in different modules,
then re-export them both from one module.

We don't want to allow this behavior.
We add a failing test to codify that this should not work.
joneshf added a commit to joneshf/purescript that referenced this issue May 26, 2019
As mentioned in the previous commit
(09bfea484ff6e0d77c028f11314763c794df8c47),
we don't want to allow re-exporting a class and a type that have
the same name.
The changes here make that a reality.

The majority of the tests are breaking because we're dependent on
`purescript-typelevel-prelude` and it violates the changes here.
See: purescript/purescript-typelevel-prelude#43
for more information.
joneshf added a commit to joneshf/purescript that referenced this issue May 26, 2019
Before, we only had conflicting exports for the same types of things.
Now that we disallow exports of different types,
we'll want to be a bit more explict in what the problem is.

Errors we'd get before looked like:
```
Export for type B.X conflicts with A.X
```
While that does convey what the problem is, we can do a bit better.

Errors now look like:
```
Export for type B.X conflicts with type class A.X
```
joneshf added a commit to joneshf/purescript that referenced this issue May 26, 2019
The changes to `purescript-typelevel-prelude` allow us to pass tests.
The transitive dependency on `purescript-prelude` required an update.
hdgarrood added a commit to purescript/purescript-typelevel-prelude that referenced this issue May 26, 2019
Refs #43, fixes #46.

RowList-related types and classes have been removed from Type.Row and
moved into Type.RowList, in order to prepare for an upcoming compiler
change whereby a module will no longer be allowed to re-export both a
type and a class of the same name; see purescript/purescript#3502
hdgarrood pushed a commit that referenced this issue May 26, 2019
* Add failing test for conflicting re-exports (#3502)

Within a module,
we cannot define a class and a data type with the same name.
The issue here is that we can define a class and a data type with
the same name in different modules,
then re-export them both from one module.

We don't want to allow this behavior.
We add a failing test to codify that this should not work.

* Disallow re-exporting same class/type name (#3502)

As mentioned in the previous commit
(09bfea484ff6e0d77c028f11314763c794df8c47),
we don't want to allow re-exporting a class and a type that have
the same name.
The changes here make that a reality.

The majority of the tests are breaking because we're dependent on
`purescript-typelevel-prelude` and it violates the changes here.
See: purescript/purescript-typelevel-prelude#43
for more information.

* Print the type of the conflicting name (#3502)

Before, we only had conflicting exports for the same types of things.
Now that we disallow exports of different types,
we'll want to be a bit more explict in what the problem is.

Errors we'd get before looked like:
```
Export for type B.X conflicts with A.X
```
While that does convey what the problem is, we can do a bit better.

Errors now look like:
```
Export for type B.X conflicts with type class A.X
```

* Update dependencies (#3502)

The changes to `purescript-typelevel-prelude` allow us to pass tests.
The transitive dependency on `purescript-prelude` required an update.
@hdgarrood
Copy link
Contributor Author

This was fixed by #3648.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants