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

feat: check if module have type with the same name #3696

Merged
merged 7 commits into from
Dec 4, 2024

Conversation

Frank-III
Copy link
Contributor

@Frank-III Frank-III commented Oct 12, 2024

resolve: #3691

the compiler already suggests something like:

Did you mean `type Request`?

`Request` is only a type, it cannot be imported as a value.

do we want to change it?

@Frank-III Frank-III marked this pull request as draft October 12, 2024 22:01
@Frank-III Frank-III marked this pull request as ready for review October 12, 2024 22:22
@giacomocavalieri
Copy link
Member

I don't think the suggestion is right here: "Did you mean type X" would produce invalid code outside of imports, the rest of the error message looks good to me though :)

@Frank-III
Copy link
Contributor Author

I don't think the suggestion is right here: "Did you mean type X" would produce invalid code outside of imports, the rest of the error message looks good to me though :)

This is what I thought! maybe we need to differentiate when we are importing or accessing it🤔

@giacomocavalieri
Copy link
Member

Yeah I think that's the right call

@lpil lpil marked this pull request as draft October 23, 2024 14:16
@lpil
Copy link
Member

lpil commented Oct 23, 2024

When you are ready for a review please un-draft this PR. Thank you!

@Frank-III Frank-III force-pushed the fix-unknown-module-value branch from cf6aa60 to f1c3971 Compare October 24, 2024 22:11
@lpil
Copy link
Member

lpil commented Dec 2, 2024

Hello! Are you still working on this one? Thanks

@Frank-III Frank-III force-pushed the fix-unknown-module-value branch from f1c3971 to 5ca6c27 Compare December 2, 2024 16:55
@Frank-III
Copy link
Contributor Author

Hi! sorry for kinda forget about this one, as discussed with @giacomocavalieri I replace type_with_same_name with a context to differentiate usage or import, but I am not very sure about the new error message for the opaque constructor now

@Frank-III Frank-III marked this pull request as ready for review December 2, 2024 17:01
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! I've left some comments inline.

compiler-core/src/type_/error.rs Outdated Show resolved Hide resolved
compiler-core/src/error.rs Outdated Show resolved Hide resolved
compiler-core/src/error.rs Outdated Show resolved Hide resolved
format!("The module `{module_name}` does not have a `{name}` value.")
let text = match context {
ModuleValueErrorContext::Import { type_with_same_name: true } =>
format!("`{name}` is only a type, it cannot be imported as a value."),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we have it show how to import it as a type, using the type keyword?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems that we already have the diagnostic to hint users to use the type keyword, do we still want to do it?

@Frank-III Frank-III force-pushed the fix-unknown-module-value branch from bed355d to d8b7807 Compare December 2, 2024 23:46
@Frank-III Frank-III requested a review from lpil December 3, 2024 22:38
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work again! Thank you Frank!!

@lpil lpil merged commit 53eb5e0 into gleam-lang:main Dec 4, 2024
12 checks passed
@Frank-III Frank-III deleted the fix-unknown-module-value branch December 4, 2024 18:32
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.

Compiler error about "unknown module value" could highlight existence of type with the same name
3 participants