-
-
Notifications
You must be signed in to change notification settings - Fork 775
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
Context aware type pprint #3312
Conversation
Hello! Are you still working on this? |
18dfb5a
to
a3af907
Compare
bf2677e
to
2e4409f
Compare
👋 I am blocked due to the seemingly complex problem of printing aliases of types instead of the original definition. I think the desidered behaviour would be to pprint the alias instead of the actual type definition. This is useful for the pattern of re-exporting private types as alias, like in lustre: However, fixing this doesn't look trivial: Proposed solution
type TypeAlias(p1, .., pn) = MyType(a1, .., an) such that example 1 // internal
pub type PubAttribute(a) =
internal.Attribute(a)
pub fn checked() -> PubAttribute(String) { todo } when printing example 1 bis // internal
pub type PubAttribute(a) =
internal.Attribute(a)
pub fn checked() -> internal.Attribute(String) { todo } // <- note we aren't using the alias This behaves in the same way as previous example. This might likely be counter-intuitive; however it looks like ocaml behaves similarly, and in some cases it might even be handy example 2 // internal
pub type PubAttribute(a, b) =
internal.Attribute(Result(b, a))
pub fn checked() -> PubAttribute(Int, Bool) { todo } Applying the alias definition, we get example 3 // internal
pub type PubAttribute(a) =
internal.Attribute(Option(a))
pub fn checked() -> internal.Attribute(Int) { todo } In this case, |
Oh and btw, would it be possible to try to merge this one first? It's done except for this couple of doubts that I mentioned, could you give me an hint with that? |
Another solution could also consist in actually adding a "TypeAlias" variant to the Type enum enum Type {
// ...
TypeAlias {
// same as "Named"
publicity: Publicity,
package: EcoString,
module: EcoString,
name: EcoString,
args: Vec<Arc<Type>>,
// but also have the type it resolves to
// so that unify() can recur on it
value: Arc<Type>,
},
} I think that's the way Elm manages to have very good messages regarding type aliases |
We don't want to do this as it results in very poor error messages and hover information- the programmer can't see what the type is so they don't know how to debug their program. Context aware type printing is implemented here so that code can be reused here. |
Got it! Just another thing, isn't this other PR implementing the same thing? Should I close mine? |
I started working on it since this PR hadn't seen any changes in several months. I'm not sure what to do if you want to continue working on this |
The other PR has now been merged, so I guess this one should be closed now |
yeah sorry about the mess :) |
Implements #2993
TODOS
Open questions
Should hovered exported types be context-aware pprinted? e.g.
Specs
Handled cases (assume the current file is
my_module.gleam
:1) types in imported modules
2) types in module that are not imported
3) types in module that are imported and renamed
4) types in modules that are imported and exposed as unqualified imports
5) types in modules that are imported and exposed as unqualified imports, and renamed
6) types defined locally
7) types from the gleam prelude