Skip to content

allow Nullable.<void> #307

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

Merged
merged 4 commits into from
Apr 1, 2014
Merged
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
2 changes: 1 addition & 1 deletion src/parser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/type.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.<variant>");
if (type.equals(Type.voidType))
throw new Error("logic flaw, cannot create Nullable.<void>");
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();
}

Expand Down
9 changes: 9 additions & 0 deletions t/compile_error/218.nullable-void-vs-void.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class C {

var m : Nullable.<void>;

function constructor() {
this.m = (function () : void {})();
}

}
3 changes: 0 additions & 3 deletions t/compile_error/218.nullable-void.jsx

This file was deleted.

6 changes: 0 additions & 6 deletions t/compile_error/219.nullable-void-deduced-from-tmplarg.jsx

This file was deleted.

12 changes: 12 additions & 0 deletions t/run/392.nullable-void.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*EXPECTED
ok
*/
class C {
var a : Nullable.<void>;
}

class _Main {
static function main (args : string[]) : void {
log "ok";
}
}
14 changes: 14 additions & 0 deletions t/run/393.nullable-void-deduced-from-tmplarg.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*EXPECTED
ok
*/
class C.<T> {
var a : Nullable.<T>;
}
class C2 {
var a : C.<void>;
}
class _Main {
static function main (args : string[]) : void {
log "ok";
}
}
15 changes: 15 additions & 0 deletions t/run/394.use-nullable-void-member.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*EXPECTED
null
*/

class C {
var m : Nullable.<void>;
}

class _Main {
static function main (args : string[]) : void {
var c = new C;

log c.m;
}
}
13 changes: 13 additions & 0 deletions t/run/395.nullable-void-vs-null.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*EXPECTED
ok
*/

class _Main {
static function main (args : string[]) : void {
var a : Nullable.<void>;

a = null;

log "ok";
}
}