Ticket #209 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

nullability not enforced

Reported by: mrbkap Assigned to: anonymous
Type: defect Priority: critical
Milestone: Component: RefImpl
Version: 4 Keywords:
Cc:

Description

Given the following program:

class Cat {
  public function meow() { print("meow"); }
}
function go(c : Cat!) {
  print("here");
  c.meow();
}
go(null);

I would expect the output to simply be the exception caused by passing null as a Cat!.

However, the current RI prints "here", indicating that the function call happened and the exception thrown in the example is thrown from the c.meow() line. I believe we should fail to convert null to a Cat! before entry into the function.

Attachments

Change History

Changed 1 year ago by jresig

  • priority changed from major to critical

A simpler case (exception expected) - and escalating:

>> function test(foo: int!){ return foo; }
>> test(null);
0

Changed 1 year ago by graydon

  • status changed from new to closed
  • resolution set to fixed

There were several inter-related RI bugs in here, but they should mostly all be fixed in revision cbc9e83...

Though your second testcase is perhaps not so good; int is presently hard-wired into the scalar conversion table for backward compatibility with ES3 primitives. So null always converts to 0 when assigned to an int, nullable or otherwise. A better case follows:

class x {}
function test(v:x!) {}
test(null);
Note: See TracTickets for help on using tickets.