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

Only allow Void in return types #11558

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
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
72 changes: 44 additions & 28 deletions src/typing/typeload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -416,34 +416,50 @@ and load_instance' ctx ptp get_params mode =
with Not_found ->
let mt = load_type_def ctx (if ptp.pos_path == null_pos then ptp.pos_full else ptp.pos_path) t in
let info = ctx.g.get_build_info ctx mt ptp.pos_full in
if info.build_path = ([],"Dynamic") then match t.tparams with
| [] -> t_dynamic
| [TPType t] -> TDynamic (Some (load_complex_type ctx true LoadNormal t))
| _ -> raise_typing_error "Too many parameters for Dynamic" ptp.pos_full
else if info.build_params = [] then begin match t.tparams with
| [] ->
info.build_apply []
| tp :: _ ->
let pt = match tp with
| TPType(_,p) | TPExpr(_,p) -> p
in
display_error ctx.com ("Too many type parameters for " ^ s_type_path info.build_path) pt;
info.build_apply []
end else begin
(* TODO: this is currently duplicated, but it seems suspcious anyway... *)
let is_rest = info.build_kind = BuildGenericBuild && (match info.build_params with [{ttp_name="Rest"}] -> true | _ -> false) in
let tl = if t.tparams = [] && not is_rest then begin match get_params with
| ParamNormal ->
begin match info.build_path with
| ([],"Dynamic") ->
begin match t.tparams with
| [] -> t_dynamic
| [TPType t] -> TDynamic (Some (load_complex_type ctx true LoadNormal t))
| _ -> raise_typing_error "Too many parameters for Dynamic" ptp.pos_full
end
| ([],"Void") ->
begin match mode with
| LoadReturn | LoadAny ->
ctx.t.tvoid
| _ ->
(* VOIDTODO: I don't think we actually want this, but let's try to get green CI *)
if has_class_flag ctx.c.curclass CExtern then
ctx.t.tvoid
else
raise_typing_error "Cannot use Void here" ptp.pos_full
end
| _ ->
if info.build_params = [] then begin match t.tparams with
| [] ->
info.build_apply []
| tp :: _ ->
let pt = match tp with
| TPType(_,p) | TPExpr(_,p) -> p
in
display_error ctx.com ("Too many type parameters for " ^ s_type_path info.build_path) pt;
info.build_apply []
end else begin
(* TODO: this is currently duplicated, but it seems suspcious anyway... *)
let is_rest = info.build_kind = BuildGenericBuild && (match info.build_params with [{ttp_name="Rest"}] -> true | _ -> false) in
let tl = if t.tparams = [] && not is_rest then begin match get_params with
| ParamNormal ->
load_params ctx info t.tparams ptp.pos_full
| ParamSpawnMonos ->
Monomorph.spawn_constrained_monos (fun t -> t) info.build_params
| ParamCustom f ->
f info None
end else
load_params ctx info t.tparams ptp.pos_full
| ParamSpawnMonos ->
Monomorph.spawn_constrained_monos (fun t -> t) info.build_params
| ParamCustom f ->
f info None
end else
load_params ctx info t.tparams ptp.pos_full
in
let t = info.build_apply tl in
maybe_build_instance ctx t get_params ptp.pos_full
in
let t = info.build_apply tl in
maybe_build_instance ctx t get_params ptp.pos_full
end
end

and load_instance ctx ?(allow_display=false) ptp get_params mode =
Expand Down Expand Up @@ -629,7 +645,7 @@ and load_complex_type' ctx allow_display mode (t,p) =
| CTFunction (args,r) ->
match args with
| [CTPath { path = {tpackage = []; tparams = []; tname = "Void" }},_] ->
TFun ([],load_complex_type ctx allow_display LoadReturn r)
TFun ([],load_complex_type ctx allow_display LoadReturn r)
| _ ->
TFun (List.map (fun t ->
let t, opt = (match fst t with CTOptional t | CTParent((CTOptional t,_)) -> t, true | _ -> t,false) in
Expand Down
3 changes: 3 additions & 0 deletions std/haxe/NoValue.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package haxe;

enum NoValue {}
6 changes: 3 additions & 3 deletions std/haxe/display/Diagnostic.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// from vshaxe
package haxe.display;

import haxe.display.JsonModuleTypes;
import haxe.display.Position.Location;
import haxe.display.Position.Range;
import haxe.display.JsonModuleTypes;

enum abstract UnresolvedIdentifierSuggestion(Int) {
var UISImport;
Expand Down Expand Up @@ -53,13 +53,13 @@ typedef ReplacableCode = {
}

enum abstract DiagnosticKind<T>(Int) from Int to Int {
final DKUnusedImport:DiagnosticKind<Void>;
final DKUnusedImport:DiagnosticKind<haxe.NoValue>;
final DKUnresolvedIdentifier:DiagnosticKind<Array<{kind:UnresolvedIdentifierSuggestion, name:String}>>;
final DKCompilerError:DiagnosticKind<String>;
final ReplacableCode:DiagnosticKind<ReplacableCode>;
final DKParserError:DiagnosticKind<String>;
final DeprecationWarning:DiagnosticKind<String>;
final InactiveBlock:DiagnosticKind<Void>;
final InactiveBlock:DiagnosticKind<haxe.NoValue>;
final MissingFields:DiagnosticKind<MissingFieldDiagnostics>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ typedef Rec2Struct<T> = {

class TypedefAbstract {
static function main() {
var r:Rec2<Void> = (null:Rec1<Void>);
var r:Rec2<haxe.NoValue> = (null:Rec1<haxe.NoValue>);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ typedef Rec2<T> = {

class TypedefTypedef {
static function main() {
var r:Rec1<Void> = (null:Rec2<Void>);
var r:Rec1<haxe.NoValue> = (null:Rec2<haxe.NoValue>);
}
}
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue10959/TestClass.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package;

@:keep
class TestClass<T, U, V = Void> {
class TestClass<T, U, V = haxe.NoValue> {
}
8 changes: 4 additions & 4 deletions tests/misc/projects/Issue10959/build.hxml.stdout
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
On Generate
-- Too Few Params --
Before: TestClass
After: TestClass<TestClass.T, TestClass.U, Void>
After: TestClass<TestClass.T, TestClass.U, haxe.NoValue>

Before: TestClass<Void>
After: TestClass<Void, TestClass.U, Void>
After: TestClass<Void, TestClass.U, haxe.NoValue>

-- Too Many Params --
Before: TestClass<Void, Int, Float, String>
Expand All @@ -15,15 +15,15 @@ Before: TestClass<Void, Int, Float>
After: TestClass<Void, Int, Float>

Before: TestClass<Void, Int>
After: TestClass<Void, Int, Void>
After: TestClass<Void, Int, haxe.NoValue>

-- Shouldn't Have Params --
Before: Void<Int, Float>
After: Void

-- Recursive Test --
Before: TestClass<TestClass, TestClass<Void, Int, Float, String>>
After: TestClass<TestClass<TestClass.T, TestClass.U, Void>, TestClass<Void, Int, Float>, Void>
After: TestClass<TestClass<TestClass.T, TestClass.U, haxe.NoValue>, TestClass<Void, Int, Float>, haxe.NoValue>

-- Fill With Specific Type --
Before: TestClass
Expand Down
2 changes: 1 addition & 1 deletion tests/misc/projects/Issue6201/compile2-fail.hxml.stderr
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Main2.hx:3: characters 7-8 : Variables of type Void are not allowed
Main2.hx:3: characters 9-13 : Cannot use Void here
3 changes: 0 additions & 3 deletions tests/misc/projects/Issue6810/.gitignore

This file was deleted.

14 changes: 0 additions & 14 deletions tests/misc/projects/Issue6810/Fail.hx

This file was deleted.

11 changes: 0 additions & 11 deletions tests/misc/projects/Issue6810/Main.hx

This file was deleted.

1 change: 0 additions & 1 deletion tests/misc/projects/Issue6810/compile-fail.hxml

This file was deleted.

6 changes: 0 additions & 6 deletions tests/misc/projects/Issue6810/compile-fail.hxml.stderr

This file was deleted.

1 change: 0 additions & 1 deletion tests/misc/projects/Issue6810/compile.hxml

This file was deleted.

2 changes: 0 additions & 2 deletions tests/misc/projects/Issue6810/indent-fail.hxml

This file was deleted.

6 changes: 0 additions & 6 deletions tests/misc/projects/Issue6810/indent-fail.hxml.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions tests/misc/projects/Issue6810/logfile-01-fail.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/misc/projects/Issue6810/logfile-02-fail.hxml

This file was deleted.

4 changes: 0 additions & 4 deletions tests/misc/projects/Issue6810/logfile-03-fail.hxml

This file was deleted.

1 change: 0 additions & 1 deletion tests/misc/projects/Issue6810/logfile-04-fail.hxml

This file was deleted.

3 changes: 0 additions & 3 deletions tests/misc/projects/Issue6810/pretty-fail.hxml

This file was deleted.

16 changes: 0 additions & 16 deletions tests/misc/projects/Issue6810/pretty-fail.hxml.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion tests/nullsafety/src/cases/TestStrict.hx
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ class TestStrict {
}
}

static function recursiveTypedef_shouldNotCrashTheCompiler(a:Recursive<Void>, b:Recursive<Void>) {
static function recursiveTypedef_shouldNotCrashTheCompiler(a:Recursive<haxe.NoValue>, b:Recursive<haxe.NoValue>) {
a = b;
}

Expand Down
15 changes: 11 additions & 4 deletions tests/unit/src/unit/issues/Issue9678.hx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ class Issue9678 extends unit.Test {
eq(2, called);
}

@:keep static function explicitVoidArg(arg:Void) {}
@:keep static function explicitVoidArg(arg:haxe.NoValue) {}
#end
}

private class C<T> {
final v:T;
public function new(v:T) this.v = v;
public function next<S>(f:()->S):C<S> return new C(f());
public function handle(cb:T->Void) {cb(v);}

public function new(v:T)
this.v = v;

public function next<S>(f:() -> S):C<S>
return new C(f());

public function handle(cb:T->Void) {
cb(v);
}
}
Loading