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

Access modifiers of definitions overwrite forward definitions #1236

Closed
ohad opened this issue Mar 26, 2021 · 6 comments
Closed

Access modifiers of definitions overwrite forward definitions #1236

ohad opened this issue Mar 26, 2021 · 6 comments

Comments

@ohad
Copy link
Collaborator

ohad commented Mar 26, 2021

Steps to Reproduce

$ cat Mutual.idr
module Mutual
private
data Foo : Type 

public export
data Foo : Type where
------------------------------
$ cat Import.idr
import Mutual

x : Foo

Expected Behavior

Type-checking Mutual.idr should report an error because the access modifiers are incompatible.

Observed Behavior

The latest definition overwrites the access modifier, and Import.idr type-checks fine.

@gallais
Copy link
Member

gallais commented Apr 27, 2021

I'm going to go ahead and tag this as good first issue because I assume it's something silly
like overwriting the existing value with a record update instead of making sure it's not set yet.

@Adowrath
Copy link
Contributor

Adowrath commented Aug 28, 2023

Right now, f76c4c4307 "fixes" this by forcing the maximum visibility to apply. This makes any combination of the three modifiers on either of the forward or actual declaration result in the higher of the two, e.g.

module Mutual

private
data Foo : Type

export
data Foo : Type where
module Mutual

export
data Foo : Type

private
data Foo : Type where

both work as if a single declaration with export was defined.

We can either leave it like this and close the issue (unsatisfying) or modify the max-merge to instead check whether they're the same and throw an error if not - this however makes the following not work anymore:

module Mutual

export
data Foo : Type

-- no visibility
data Foo : Type where

Which, while technically consistent (no visibility == private, and private != export), means you would need to repeat the same visibility in both places. This breaks code in an unsatisfying way, while the general idea of removing the max-check itself breaks code that relied on what seemed like buggy behaviour?

Making the above export+<nothing> declaration possible would require modifying either Visibility - add Unspecified which means "Can be overriden, otherwise means private" or change most occurrences of Visibility to Maybe Visibility, but could be done.

I'll put this up here before I tackle solving it, so please add your input which solution would be the best!

Might even be a good idea to add votes, so:

  1. 👀 Leave situation as-is
  2. 🚀 Change max-merge to equals check without Visibility change
  3. 🎉 Change max-merge to equals check with the Visibility change

@gallais
Copy link
Member

gallais commented Aug 28, 2023

If only we had a gadget that allowed us to express that something is the default
without conflating it with the default value it takes. 🤔

http://gallais.github.io/blog/ceci-pas-default

@Adowrath
Copy link
Contributor

If only we had a gadget that allowed us to express that something is the default without conflating it with the default value it takes. 🤔

http://gallais.github.io/blog/ceci-pas-default

Are you suggesting I use this to implement Nr. 3? Or just a general comment?
Where would I place it? src/Libraries/Data/WithDefault.idr or would it warrant a placement in base?

@gallais
Copy link
Member

gallais commented Aug 28, 2023

Yeah I think it'd be nice to complain if there are conflicting declarations which means changing
the merge strategy to take into account lack of value vs. value that happens to equal the default.

@emdash
Copy link

emdash commented Jul 25, 2024

Is this still an issue? It seems like we get correctly warned now...

gallais added a commit to gallais/Idris2 that referenced this issue Jul 25, 2024
This issue was closed.
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

4 participants