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

TypeCastError isn't raised when casting scalar value #10021

Closed
Blacksmoke16 opened this issue Dec 3, 2020 · 2 comments
Closed

TypeCastError isn't raised when casting scalar value #10021

Blacksmoke16 opened this issue Dec 3, 2020 · 2 comments

Comments

@Blacksmoke16
Copy link
Member

https://play.crystal-lang.org/#/r/a1tf

1.as String
Showing last frame. Use --error-trace for full trace.

error in line 1
Error: can't cast Int32 to String

I would have expected this to work like the example in the API docs, where it actually raises a TypeCastError.

@jhass
Copy link
Member

jhass commented Dec 3, 2020

TypeCastError is a runtime error, it happens when resolving a union to a type that doesn't match its actual value at runtime.

You're looking at a compile error here.

Also remember, casting is interpreting the same value (the same bytes) as a different type. Conversion or coercion is producing an equivalent or comparable value in a different type. as does casting only.

Compare https://carc.in/#/r/a1tp

@Blacksmoke16
Copy link
Member Author

Ahh rip, don't mind me 🙈.

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

No branches or pull requests

2 participants