diff --git a/src/parser.jsx b/src/parser.jsx index f1febe75..30b11d7e 100644 --- a/src/parser.jsx +++ b/src/parser.jsx @@ -1980,7 +1980,7 @@ class Parser { function _nullableTypeDeclaration () : Type { if (this._expect(".") == null || this._expect("<") == null) return null; - var baseType = this._typeDeclaration(false); + var baseType = this._typeDeclaration(true); if (baseType == null) return null; if (this._expect(">") == null) diff --git a/src/type.jsx b/src/type.jsx index 45747772..6ca3de83 100644 --- a/src/type.jsx +++ b/src/type.jsx @@ -63,7 +63,7 @@ abstract class Type { } function toNullableType (force : boolean) : Type { - if (force || this instanceof PrimitiveType) { + if (force || this instanceof PrimitiveType || this.equals(Type.voidType)) { return new NullableType(this); } return this; @@ -202,7 +202,7 @@ class VoidType extends Type { } override function isConvertibleTo (type : Type) : boolean { - return false; + return type.equals(Type.voidType); } override function getClassDef () : ClassDefinition { @@ -363,13 +363,11 @@ class NullableType extends Type { function constructor (type : Type) { if (type.equals(Type.variantType)) throw new Error("logic flaw, cannot create Nullable."); - if (type.equals(Type.voidType)) - throw new Error("logic flaw, cannot create Nullable."); this._baseType = type instanceof NullableType ? (type as NullableType)._baseType : type; } override function instantiate (instantiationContext : InstantiationContext, allowVoid : boolean) : Type { - var baseType = this._baseType.resolveIfNullable().instantiate(instantiationContext, allowVoid); + var baseType = this._baseType.resolveIfNullable().instantiate(instantiationContext, true); return baseType.toNullableType(); } diff --git a/t/compile_error/218.nullable-void-vs-void.jsx b/t/compile_error/218.nullable-void-vs-void.jsx new file mode 100644 index 00000000..5cafb823 --- /dev/null +++ b/t/compile_error/218.nullable-void-vs-void.jsx @@ -0,0 +1,9 @@ +class C { + + var m : Nullable.; + + function constructor() { + this.m = (function () : void {})(); + } + +} diff --git a/t/compile_error/218.nullable-void.jsx b/t/compile_error/218.nullable-void.jsx deleted file mode 100644 index 45809314..00000000 --- a/t/compile_error/218.nullable-void.jsx +++ /dev/null @@ -1,3 +0,0 @@ -class _Main { - var a : Nullable.; -} diff --git a/t/compile_error/219.nullable-void-deduced-from-tmplarg.jsx b/t/compile_error/219.nullable-void-deduced-from-tmplarg.jsx deleted file mode 100644 index ef0cedf4..00000000 --- a/t/compile_error/219.nullable-void-deduced-from-tmplarg.jsx +++ /dev/null @@ -1,6 +0,0 @@ -class C. { - var a : Nullable.; -} -class C2 { - var a : C.; -} diff --git a/t/run/392.nullable-void.jsx b/t/run/392.nullable-void.jsx new file mode 100644 index 00000000..84c1cbd2 --- /dev/null +++ b/t/run/392.nullable-void.jsx @@ -0,0 +1,12 @@ +/*EXPECTED +ok +*/ +class C { + var a : Nullable.; +} + +class _Main { + static function main (args : string[]) : void { + log "ok"; + } +} diff --git a/t/run/393.nullable-void-deduced-from-tmplarg.jsx b/t/run/393.nullable-void-deduced-from-tmplarg.jsx new file mode 100644 index 00000000..c2a1ad97 --- /dev/null +++ b/t/run/393.nullable-void-deduced-from-tmplarg.jsx @@ -0,0 +1,14 @@ +/*EXPECTED +ok +*/ +class C. { + var a : Nullable.; +} +class C2 { + var a : C.; +} +class _Main { + static function main (args : string[]) : void { + log "ok"; + } +} diff --git a/t/run/394.use-nullable-void-member.jsx b/t/run/394.use-nullable-void-member.jsx new file mode 100644 index 00000000..cde0e457 --- /dev/null +++ b/t/run/394.use-nullable-void-member.jsx @@ -0,0 +1,15 @@ +/*EXPECTED +null +*/ + +class C { + var m : Nullable.; +} + +class _Main { + static function main (args : string[]) : void { + var c = new C; + + log c.m; + } +} diff --git a/t/run/395.nullable-void-vs-null.jsx b/t/run/395.nullable-void-vs-null.jsx new file mode 100644 index 00000000..de33532c --- /dev/null +++ b/t/run/395.nullable-void-vs-null.jsx @@ -0,0 +1,13 @@ +/*EXPECTED +ok +*/ + +class _Main { + static function main (args : string[]) : void { + var a : Nullable.; + + a = null; + + log "ok"; + } +}