[Open Discussion] Cast Specification
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- compilers
Research direction
Start by reviewing the existing Haxe 4 cast forms described in the issue: safe cast, unsafe cast, Std.downcast, and runtime type checks. Compare the proposed syntax and behavior changes, then use the discussion to determine whether the proposal has a settled direction; done requires an agreed specification rather than a single localized edit.
Written by the indexing model from the issue text.
Description
ATM in Haxe 4 we have different ways to cast a type to another:
- the "safe cast", which is
cast(expr,T)- at compilation : will ensure that the type of
expris a subtype ofTso the cast is valid - at runtime : will perform the typecheck and throw if not satisified
- at compilation : will ensure that the type of
- the "safe downcast", which is
Std.downcast(expr,T)- very similar to the safe cast, but returns null instead of throwing an error if the cast is not satisfied.
- can be used instead of a
expr is Tcombined with acast(expr,T)
- the "unsafe cast", which is
var v : T = cast expr- no compile time check is performed
- runtime check is only performed on static targets, which will throw an exception on these targets only. On JS for example no error will occur
- sadly that's at the same time the most unsafe AND the shortest to write.
- additionally we have
expr is TandStd.isOfType(v,T)to check if an expression is of a given type at runtime, the Std.isOfType allowing to specify the type as a variable.
I know it's a bit late but I think we should change this for Haxe 5, as this is the kind of big change we except and allow in a major release.
My proposal would be to:
- make the current unsafe cast syntax do the same thing as the safe cast, so
var v : T = cast exprwould be the same asvar v = cast(expr,T). - introduce a
Std.unsafeCast(expr)that would replace the unsafe cast, but then be much more explicit. - promote
downcastto a keyword and allow bothvar v : T = downcast exprandvar v = downcast(expr,T)the same as the safe cast but with a null result.
- Dominant language
- No language data
- Stars
- 120
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from HaxeFoundation/haxe-evolution
-
Difficulty 1/5 Under an hour Newbie friendliness 5/100
HaxeFoundation/haxe-evolution#126 · 2 comments · 1 reaction ·
-
License for RFCsOpen
Difficulty 5/5 Over a week Newbie friendliness 35/100
HaxeFoundation/haxe-evolution#121 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
HaxeFoundation/haxe-evolution#114 · 8 comments · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
HaxeFoundation/haxe-evolution#107 · 1 comment · 1 reaction ·
-
EcmaScript 4 syntaxOpen
Difficulty 5/5 Over a week Newbie friendliness 30/100
HaxeFoundation/haxe-evolution#106 · 1 comment · 3 reactions ·
All issues in HaxeFoundation/haxe-evolution
Similar issues
-
node:url: url.parse and url.resolve report name parse/resolve instead of Node's urlParse/urlResolveOpenarea:stdlib effort:S impact:low parity type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bad-antics/lateralus-lang#880 · 1 comment ·
Maintainers usually reply within 1 day
-
bug fixed form parser medium priority tokenizer
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 Under an hour Newbie friendliness 80/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
swc-project/swc-next-issues#817 ·