Skip to content

Commit 6704e4e

Browse files
committed
Merge pull request #307 from jsx/wasabiz/feature/allow-nullable-void
allow Nullable.<void>
2 parents 1e07252 + f332a0c commit 6704e4e

9 files changed

+67
-15
lines changed

src/parser.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1980,7 +1980,7 @@ class Parser {
19801980
function _nullableTypeDeclaration () : Type {
19811981
if (this._expect(".") == null || this._expect("<") == null)
19821982
return null;
1983-
var baseType = this._typeDeclaration(false);
1983+
var baseType = this._typeDeclaration(true);
19841984
if (baseType == null)
19851985
return null;
19861986
if (this._expect(">") == null)

src/type.jsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ abstract class Type {
6363
}
6464

6565
function toNullableType (force : boolean) : Type {
66-
if (force || this instanceof PrimitiveType) {
66+
if (force || this instanceof PrimitiveType || this.equals(Type.voidType)) {
6767
return new NullableType(this);
6868
}
6969
return this;
@@ -202,7 +202,7 @@ class VoidType extends Type {
202202
}
203203

204204
override function isConvertibleTo (type : Type) : boolean {
205-
return false;
205+
return type.equals(Type.voidType);
206206
}
207207

208208
override function getClassDef () : ClassDefinition {
@@ -363,13 +363,11 @@ class NullableType extends Type {
363363
function constructor (type : Type) {
364364
if (type.equals(Type.variantType))
365365
throw new Error("logic flaw, cannot create Nullable.<variant>");
366-
if (type.equals(Type.voidType))
367-
throw new Error("logic flaw, cannot create Nullable.<void>");
368366
this._baseType = type instanceof NullableType ? (type as NullableType)._baseType : type;
369367
}
370368

371369
override function instantiate (instantiationContext : InstantiationContext, allowVoid : boolean) : Type {
372-
var baseType = this._baseType.resolveIfNullable().instantiate(instantiationContext, allowVoid);
370+
var baseType = this._baseType.resolveIfNullable().instantiate(instantiationContext, true);
373371
return baseType.toNullableType();
374372
}
375373

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class C {
2+
3+
var m : Nullable.<void>;
4+
5+
function constructor() {
6+
this.m = (function () : void {})();
7+
}
8+
9+
}

t/compile_error/218.nullable-void.jsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

t/compile_error/219.nullable-void-deduced-from-tmplarg.jsx

Lines changed: 0 additions & 6 deletions
This file was deleted.

t/run/392.nullable-void.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*EXPECTED
2+
ok
3+
*/
4+
class C {
5+
var a : Nullable.<void>;
6+
}
7+
8+
class _Main {
9+
static function main (args : string[]) : void {
10+
log "ok";
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*EXPECTED
2+
ok
3+
*/
4+
class C.<T> {
5+
var a : Nullable.<T>;
6+
}
7+
class C2 {
8+
var a : C.<void>;
9+
}
10+
class _Main {
11+
static function main (args : string[]) : void {
12+
log "ok";
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*EXPECTED
2+
null
3+
*/
4+
5+
class C {
6+
var m : Nullable.<void>;
7+
}
8+
9+
class _Main {
10+
static function main (args : string[]) : void {
11+
var c = new C;
12+
13+
log c.m;
14+
}
15+
}

t/run/395.nullable-void-vs-null.jsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*EXPECTED
2+
ok
3+
*/
4+
5+
class _Main {
6+
static function main (args : string[]) : void {
7+
var a : Nullable.<void>;
8+
9+
a = null;
10+
11+
log "ok";
12+
}
13+
}

0 commit comments

Comments
 (0)