Skip to content
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

Possibility to call non-existing method on array element without explicit 'any' #8593

Open
Renegatto opened this issue Feb 20, 2021 · 0 comments
Labels
bug Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program)

Comments

@Renegatto
Copy link

Flow version: 0.145.0

/* @flow */
class Animal { }
class Dog extends Animal { bark() { } }
class Cat extends Animal { meow() { } }

const arr1 = [new Dog(), new Dog()];
const arr2: Animal[] = arr1;
arr2.push(new Cat()); // arr1 == [new Dog(), new Dog(), new Cat()]

arr1.forEach(c => c.bark()); //will fail at runtime with 'c.bark is not a function'

Expected behavior

Any sort of static checking error.

Actual behavior

JS runtime error: c.bark is not a function

Adding explicit type annotation to arr1 leads to type error (expected behavior).

@SamChou19815 SamChou19815 added Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program) and removed needs triage labels Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Typing: soundness No false negatives (type checker claims that there is no error in the incorrect program)
Projects
None yet
Development

No branches or pull requests

2 participants