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

NTI @template THIS issue #1437

Closed
supersteves opened this issue Jan 25, 2016 · 3 comments
Closed

NTI @template THIS issue #1437

supersteves opened this issue Jan 25, 2016 · 3 comments
Assignees
Labels

Comments

@supersteves
Copy link
Contributor

Trying to use covariant return type like this, in NTI:

  /** @param {Object} obj */
  var helper = function(obj) {}; // in externs

  /**
   * @this {THIS}
   * @return {THIS}
   * @template THIS
   */
  x() {
    this.something();
    helper(this);
    return this;
  }

Warnings generated:

input0:9: WARNING - Cannot access property something of non-object type THIS.
    this.something();
    ^

input0:10: WARNING - Invalid type for parameter 1 of function helper.
expected : Object|null
found    : THIS

    helper(this);

I think both should be inferred as valid.

https://closure-compiler-debugger.appspot.com/#input0%3Dclass%2520X%2520%257B%250A%250A%2520%2520%252F**%250A%2520%2520%2520*%2520%2540this%2520%257BTHIS%257D%250A%2520%2520%2520*%2520%2540return%2520%257BTHIS%257D%250A%2520%2520%2520*%2520%2540template%2520THIS%250A%2520%2520%2520*%252F%250A%2520%2520x()%2520%257B%250A%2520%2520%2520%2520this.something()%253B%250A%2520%2520%2520%2520helper(this)%253B%250A%2520%2520%2520%2520return%2520this%253B%250A%2520%2520%257D%250A%250A%2520%2520something()%2520%257B%2520%250A%2520%2520%2520%2520console.log(this)%253B%2520%250A%2520%2520%257D%250A%250A%257D%26input1%26conformanceConfig%26externs%3D%252F**%2520%2540param%2520%257BObject%257D%2520obj%2520*%252F%250Avar%2520helper%2520%253D%2520function(obj)%2520%257B%257D%253B%250A%26refasterjs-template%26includeDefaultExterns%3D1%26CHECK_SYMBOLS%3D1%26CHECK_TYPES%3D1%26CHECK_TYPES_NEW_INFERENCE%3D1%26LANG_IN_IS_ES6%3D1%26MISSING_PROPERTIES%3D1%26PRESERVE_TYPE_ANNOTATIONS%3D1%26PRETTY_PRINT%3D1%26TRANSPILE%3D1

Related to #1411

@dimvar
Copy link
Contributor

dimvar commented Jan 25, 2016

The right fix for this is to handle bounded generics in NTI. Without that, we probably want to warn here. We don't know anything about the type variable, we don't know if it's an object, or what properties it has. So, without bounded generics, you have to cast for the time being.

@dimvar dimvar closed this as completed Jan 25, 2016
@dimvar dimvar added the NTI label Jan 25, 2016
@dimvar dimvar self-assigned this Jan 25, 2016
@supersteves
Copy link
Contributor Author

#576

@supersteves
Copy link
Contributor Author

Thanks @dimvar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants