Flow: Flow crashes when using `||` or ternary with constructors

Created on 24 Oct 2019  路  2Comments  路  Source: facebook/flow


The following code causes Flow server to crash (simplified example):

let err = new TypeError();
let constructor = typeof err.constructor === 'function' ? err.constructor : Error;
const clone = Object.create(constructor.prototype);

Whereas this doesn't:

let err = new TypeError();
let constructor = err.constructor;
if (typeof constructor !== 'function') {
  constructor = Error;
}
const clone = Object.create(constructor.prototype);

Flow version: 0.110.1, 0.107.0

Expected behavior

No errors!

Actual behavior

Flow server crash.
Try Flow console output:

add_output: no source for error: EInvalidPrototype (: "empty prototype object"):

  • Link to Try-Flow or Github repo:

Crash examples:
Try Flow (ternary)
Try Flow (pipe)

Working example:
Try Flow (if statement)

Crash bug

All 2 comments

Thanks for the excellent bug report! @panagosg7 has agreed to take a look.

Fixed by c66358199e8e578c51215271bfbbbe1514e27cfb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Beingbook picture Beingbook  路  3Comments

ghost picture ghost  路  3Comments

mmollaverdi picture mmollaverdi  路  3Comments

jamiebuilds picture jamiebuilds  路  3Comments

john-gold picture john-gold  路  3Comments