Default value for enum parameters
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Domain
- compilers
Research direction
Start with the enum constructor examples in the issue and compare the requested behavior with Haxe's function default-values documentation. Identify the compiler entry points and tests for enum parameter parsing and construction, then define completion as supporting the requested default-value syntax while preserving existing optional-parameter behavior and validation.
Written by the indexing model from the issue text.
Description
I was surprised to find that while
enum Schedule {
Hourly(?minute:Int);
// ...
}
is possible, this is not:
enum Schedule {
Hourly(minute:Int=1); // characters 18-19 : Unexpected =
// ...
}
Right now I have to do additional null-checks on enums with optional parameters like so
var instance = new MyClass(Schedule.Hourly());
function MyClass {
var schedule:Schedule;
public function new(var schedule:Schedule){
// validate schedule
switch (schedule) {
case Hourly(minute):
// check for null and apply a default value if found
if(minute == null) {
minute = 1;
schedule = Schedule.Hourly(minute);
} else if (minute < 0 || minute > 59)
throw "Hourly.Minute must be >= 0 and < 60";
}
// ...
}
this.schedule = schedule;
}
}
instead of simply:
var instance = new MyClass(Schedule.Hourly());
function MyClass {
var schedule:Schedule;
public function new(var schedule:Schedule) {
// validate schedule
switch (schedule) {
case Hourly(minute):
if (minute < 0 || minute > 59)
throw "Hourly.Minute must be >= 0 and < 60";
// ...
}
this.schedule = schedule;
}
}
Therefore I would request adding default value behaviour for enums as specified here https://haxe.org/manual/types-function-default-values.html
- 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 25/100
HaxeFoundation/haxe-evolution#120 · 9 comments · 5 reactions ·
-
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 ·
All issues in HaxeFoundation/haxe-evolution
Similar issues
-
clang:frontend clang:openmp crash
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
llvm/llvm-project#245442 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
module: exir
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
pytorch/executorch#25620 ·
Maintainers usually reply within 1 day
-
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 74/100
rust-lang/miri#5673 · 3 comments ·
Maintainers usually reply within 1 day