Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions tests/nullsafety/src/cases/TestStrict.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1540,3 +1540,110 @@ class BinopFlow {
});
}
}

@:build(Validator.checkFields())
class ConstructorThrowWithElse {
final s:String;

public function new() {
if (Math.random() > 0.5) {
throw "no";
} else {
s = "foo";
}
}
}

@:build(Validator.checkFields())
class ConstructorThrowNoElse {
final s:String;

public function new() {
if (Math.random() > 0.5) {
throw "no";
}
s = "foo";
}
}

@:build(Validator.checkFields())
class ConstructorThrowBothBranches {
final s:String;

public function new() {
if (Math.random() > 0.5) {
throw "no";
} else {
throw "also no";
}
}
}

@:build(Validator.checkFields())
class ConstructorReturn {
@:shouldFail final s:String;

public function new() {
if (Math.random() > 0.5) {
return;
} else {
s = "foo";
}
}
}

@:build(Validator.checkFields())
class ConstructorMixedThrowReturn {
final s:String;

public function new() {
if (Math.random() > 0.5) {
// Throw branch: doesn't need to initialize fields
throw "error";
} else {
// Return branch: must initialize all fields
s = "three";
return;
}
}
}

@:build(Validator.checkFields())
class ConstructorMixedThrowReturnFail {
@:shouldFail final s:String;

public function new() {
if (Math.random() > 0.5) {
// Throw branch: doesn't need to initialize fields
throw "error";
} else {
// Return branch: must initialize all fields, but doesn't - should fail
return;
}
}
}

@:build(Validator.checkFields())
class ConstructorEarlyReturnNoElse {
@:shouldFail final s:String;

public function new() {
if (Math.random() > 0.5) {
return;
}
s = "foo";
}
}

@:build(Validator.checkFields())
class ConstructorEarlyReturnWithElse {
@:shouldFail final s:String;

public function new() {
if (Math.random() > 0.5) {
return;
} else {
s = "foo";
}
}
}
Loading