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

remove bad type inference behavior for enum identifiers #23588

Merged
merged 1 commit into from
May 10, 2024

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented May 9, 2024

refs #23586 (comment)

In #20091 a bad kind of type inference was mistakenly left in where if an identifier abc had an expected type of an enum type Enum, and Enum had a member called abc, the identifier would change to be that enum member. This causes bugs where a local symbol can have the same name as an enum member but have a different value. I had assumed this behavior was removed since but it wasn't, and CI seems to pass having it removed.

A separate PR needs to be made for the 2.0 branch because these lines were moved around during a refactoring in #23123 which is not in 2.0.

@metagn metagn changed the title test removing weird enum identifier type inference remove bad type inference behavior for enum identifiers May 10, 2024
@metagn metagn marked this pull request as ready for review May 10, 2024 08:16
@metagn
Copy link
Collaborator Author

metagn commented May 10, 2024

CI passes, it seems to be okay to remove this, will make PR for version-2-0 if this is merged

@Araq Araq merged commit c101490 into nim-lang:devel May 10, 2024
19 checks passed
@Araq
Copy link
Member

Araq commented May 10, 2024

Superb work, thanks!

Copy link
Contributor

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from c101490

Hint: mm: orc; opt: speed; options: -d:release
178549 lines; 8.288s; 752.918MiB peakmem

metagn added a commit to metagn/Nim that referenced this pull request May 10, 2024
Araq pushed a commit that referenced this pull request May 14, 2024
fixes #23596

When importing a module and declaring an overloadable symbol with the
same name as the module in the same scope, the module symbol can take
over and make the declared overload impossible to access. Previously
enum overloading had a quirk that bypassed this in a context where a
specific enum type was expected but this was removed in #23588. Now this
is bypassed in every place where a specific type is expected since
module symbols don't have a type and so wouldn't be compatible anyway.

But the issue still exists in places where no type is expected like `let
x = modulename`. I don't see a way of fixing this without nerfing module
symbols to the point where they're not accessible by default, which
might break some macro code.
metagn added a commit to metagn/Nim that referenced this pull request May 15, 2024
Araq pushed a commit that referenced this pull request Aug 17, 2024
fixes #23689

Normally pure enum symbols only "exist" in lookup if nothing else with
the same name is in scope. But if an expression is expected to be an
enum type, we know that ambiguity can be resolved between different
symbols based on their type, so we can include the normally inaccessible
pure enum fields in the ambiguity resolution in the case that the
expected enum type is actually a pure enum. This handles the use case in
the issue of the type inference for enums reverted in #23588.

I know pure enums are supposed to be on their way out so this might seem
excessive, but the `pure` pragma can't be removed in the code in the
issue due to a redefinition error, they have to be separated into
different modules. Normal enums can still resolve the ambiguity here
though. I always think about making a list of all the remaining use
cases for pure enums and I always forget.

Will close #23694 if CI passes
narimiran pushed a commit that referenced this pull request Aug 31, 2024
refs
#23586 (comment)

In #20091 a bad kind of type inference was mistakenly left in where if
an identifier `abc` had an expected type of an enum type `Enum`, and
`Enum` had a member called `abc`, the identifier would change to be that
enum member. This causes bugs where a local symbol can have the same
name as an enum member but have a different value. I had assumed this
behavior was removed since but it wasn't, and CI seems to pass having it
removed.

A separate PR needs to be made for the 2.0 branch because these lines
were moved around during a refactoring in #23123 which is not in 2.0.

(cherry picked from commit c101490)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants