aabtop / reify

Reify lets you embed a customized TypeScript runtime within a C++ application.
MIT License
6 stars 0 forks source link

Blank return statements do not raise an exception from the TS compiler. #21

Closed aabtop closed 4 years ago

aabtop commented 4 years ago

A situation arose where the code:

  build(): h.Region3 {
    return
    h.Difference3({
      a: h.Difference3({
        a: Box3(this.width, this.length, this.height),
        b: Box3(this.width - (this.wall_thickness * 2), this.length - (this.wall_thickness * 2), this.height - (this.wall_thickness * 2)),
      }),
      b: h.Transform3({ source: Box3(2, 2, 2), transform: h.Translate3([0, 0, 3]) })
    });
  }

Resulted in a segmentation fault. What was happening was that the first return statement on its own line was being interpreted as a statement on its own, and somehow getting past the type checker as it is clearly not returning a h.Region3 here.

Perhaps there are some TypeScript compiler settings that would enable more strict checking of types here?

Attached is the full file that seg faults on hypo bad_house.ts Main house.

aabtop commented 4 years ago

Lots of discussion over at https://github.com/microsoft/TypeScript/issues/5916 about this. Seems like we should enable --strictNullChecks and/or --noImplicitReturns.

aabtop commented 4 years ago

Fixed in e690817e020e9d94f61b14751281c1e70fb45e8a .