google / google/closure-compiler

Improper @extends generates bad code with no error message

Open
#3,126 3 comments 0 reactions 0 assignees View on GitHub
internal-issue-created triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Input:

```js
/** @abstract */
class Base {
/** @return {string} */
foo() {}
other() { return 'other'; }
}

/** @extends {Base} */
class Derived {
foo() {
return 'derived';
}
}

/** @param {!Base} x */
function f(x) {
console.log(x.foo());
console.log(x.other());
}

f(new Derived());
```

Output:

```js
var a=new function(){};console.log("derived");console.log(a.a());
```

Note that `a.a()` doesn't exist. I think the code is in error in that it says `@extends` without adding any run-time extension, but in that case I think it should be rejected by the compiler.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.