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

REPL: describing types doesn't work #96

Open
ghost opened this issue Jun 10, 2020 · 1 comment
Open

REPL: describing types doesn't work #96

ghost opened this issue Jun 10, 2020 · 1 comment
Assignees

Comments

@ghost
Copy link

ghost commented Jun 10, 2020

I noticed that gomacro can describe for example imports and functions when using the repl, like:

>import "fmt"
>fmt // works good
>fmt.Sprintf // works good
>fmt.State // doesn't work: package fmt "fmt" has no symbol State
>uint8 // doesn't work: undefined identifier: uint8

It would be nice to get the information, that the type definition exists in the scope, and maybe how it looks like (similar to the output for a func)

@cosmos72
Copy link
Owner

cosmos72 commented Jun 10, 2020

This is an accidental extension to Go language:

import "fmt"
fmt
foo := fmt

I.e. in gomacro, packages are values - although you can do very little with variables containing a package. I kept this extension because it can be useful for debugging.
In compiled Go, packages are not values - you cannot store them in variables or pass them as function arguments.

I did not add the same extension to types - you cannot store a type in a variable. Thus a single fmt.State or uint8 is not a valid expression.
Thinking about it, adding an implicit conversion from type to value will probably break existing code, as for example uint8(1), which would become ambiguous: it could mean either "convert 1 to type uint8" or "call the function/closure uint8 with the single argument 1"

Maybe I could add a :show special command that works both on expressions and types.

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

1 participant