Skip to content

Add Crystal::Repl::Value#runtime_type#14156

Merged
bcardiff merged 4 commits intocrystal-lang:masterfrom
bcardiff:interpreter/runtime-type
Sep 3, 2024
Merged

Add Crystal::Repl::Value#runtime_type#14156
bcardiff merged 4 commits intocrystal-lang:masterfrom
bcardiff:interpreter/runtime-type

Conversation

@bcardiff
Copy link
Member

@bcardiff bcardiff commented Jan 2, 2024

This PR adds Crystal::Repl::Value#runtime_type

This can be used to show type information as part of the repl or others clients: eg 1 :: Int32 <: (String | Int32) when instructed (I'm not fully sure about the syntax)

end

def runtime_type : Crystal::Type
if type.is_a?(Crystal::UnionType)
Copy link
Member

Choose a reason for hiding this comment

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

issue: This method seems incomplete with handling only union types. What about virtual types?
#runtime_type of Bar.new || Foo.new (with Bar < Foo) should return Bar, not Foo+.
So I think we'll need branches for VirtualType and VirtualMetaclassType.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

It should definitely match value.class. What would be the preferred way to have a single source of truth for that @HertzDevil ?

Copy link
Contributor

Choose a reason for hiding this comment

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

For now just cross-reference the two places in comments, since there are probably even more places than those two that need to agree on the ABI (normal codegen and maybe stdlib)

@straight-shoota straight-shoota changed the title Add Crystal::Repl::Value#runtime_type Add Crystal::Repl::Value#runtime_type Jan 2, 2024
@bcardiff bcardiff force-pushed the interpreter/runtime-type branch from 5ad9a68 to 371b20c Compare August 30, 2024 22:51
@bcardiff
Copy link
Member Author

I finally addressed the feedback. I'm not sure the current #type implementation for virtual types is good

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
@bcardiff bcardiff merged commit 6ee4eb9 into crystal-lang:master Sep 3, 2024
@straight-shoota straight-shoota added this to the 1.14.0 milestone Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants