Open martin-henz opened 1 year ago
@zhaojj2209 any comments? Are the types available in the AST?
We should be able to retrieve the types from the type environment if we are able to pause execution at the exact line. Perhaps we can look into breakpoint support? E.g. Insert a debugger statement at the line where we want to show the type, then modify the type checking function to return the type environment at the point of encountering the debugger statement.
We should be able to retrieve the types from the type environment if we are able to pause execution at the exact line. Perhaps we can look into breakpoint support? E.g. Insert a debugger statement at the line where we want to show the type, then modify the type checking function to return the type environment at the point of encountering the debugger statement.
Why should we do this at runtime? We can (re)run the type checker when the user wants a type, and look for the right variable (using line and column info). [Would be nice to find the type of expressions, too.]
Apologies for the confusion, yes we should do this at compile time.
The type checker recurses through the AST to get the type of every node. We can perhaps modify the function to take in the location of a node and "save" the type for that particular node when typechecking. This way, we would be able to get the type of any node.
Update: The hotkey is still documented, but disabled for all Source versions, including Source Typed.
Currently, the deprecated type inference feature is used for the show type shortcut:
(activate the feature with control-shift-m: https://github.com/source-academy/frontend/wiki/Source-Academy-Keyboard-Shortcuts)
We should disable this for the untyped Source variants, and switch this to the declared type of names (or
any
if no type is declared) for the typed variants of Source.