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

Mismatching return types not detected #2783

Open
wallw-teal opened this issue Jan 10, 2018 · 2 comments
Open

Mismatching return types not detected #2783

wallw-teal opened this issue Jan 10, 2018 · 2 comments
Assignees

Comments

@wallw-teal
Copy link
Contributor

wallw-teal commented Jan 10, 2018

Inferred union types are not producing warnings if they differ from the declared return type.

Example:

/**
 * @typedef {{name: !string, type: !string}}
 */
var SimpleColumn;

/**
 * @typedef {{name: !string, field: !string, type: !string, width: number}}
 */
var ComplexColumn;

/**
 * @return {Array<!ComplexColumn>}
 */
var getComplexColumns = function() {
  return [];
}

/**
 * @return {Array<!SimpleColumn>}
 */
var getSimpleColumns = function() {
  return [];
}

/**
 * @return {Array<!ComplexColumn>}
 */
var getColumns = function() {
  var columns;

  if (new Date().getTime() % 2 === 0) {
    columns = getComplexColumns();
  } else {
    columns = getSimpleColumns();
  }

  return columns; // should have warning for mismatching return type
}

The warning is produced properly on NTI. Is that still considered experimental or is it something that we should switch to?

Flags:

--dependency_mode STRICT --source_map_format V3 --create_source_map dist/build.min.map --summary_detail_level 3 --language_in ECMASCRIPT_2015 --warning_level VERBOSE --jscomp_error='accessControls' --jscomp_error='ambiguousFunctionDecl' --jscomp_error='checkRegExp' --jscomp_error='checkTypes' --jscomp_error='checkVars' --jscomp_error='conformanceViolations' --jscomp_error='const' --jscomp_error='constantProperty' --jscomp_error='deprecatedAnnotations' --jscomp_error='duplicateMessage' --jscomp_error='es5Strict' --jscomp_error='externsValidation' --jscomp_error='fileoverviewTags' --jscomp_error='functionParams' --jscomp_error='globalThis' --jscomp_error='internetExplorerChecks' --jscomp_error='invalidCasts' --jscomp_error='misplacedTypeAnnotation' --jscomp_error='missingGetCssName' --jscomp_error='missingPolyfill' --jscomp_error='missingProperties' --jscomp_error='missingRequire' --jscomp_error='missingReturn' --jscomp_error='moduleLoad' --jscomp_error='msgDescriptions' --jscomp_error='nonStandardJsDocs' --jscomp_error='missingSourcesWarnings' --jscomp_error='suspiciousCode' --jscomp_error='strictModuleDepCheck' --jscomp_error='typeInvalidation' --jscomp_error='undefinedNames' --jscomp_error='undefinedVars' --jscomp_error='unknownDefines' --jscomp_error='unusedLocalVariables' --jscomp_error='useOfGoogBase' --jscomp_error='uselessCode' --jscomp_error='underscore' --jscomp_error='visibility' --jscomp_warning='deprecated' --jscomp_warning='missingOverride' --jscomp_warning='unusedPrivateMembers' --jscomp_off='es3' --jscomp_off='newCheckTypes' --jscomp_off='reportUnknownTypes' --jscomp_off='missingOverride' --compilation_level ADVANCED --generate_exports --output_wrapper (function(){%output%}).call(window); --output_manifest dist/gcc-manifest --js='src/**.js' --entry_point goog:main --js_output_file dist/build.min.js
wallw-teal added a commit to wallw-teal/opensphere that referenced this issue Jan 10, 2018
There was an inferred union type here {Array<!(ColumnDefinition\|FeatureTypeColumn)>} that the

compiler is not detecting as a mismatch with the declared type. I opened

google/closure-compiler#2783 with the compiler. This issue was causing

filters programmatically created from histogram bins to fail.
wallw-teal added a commit to wallw-teal/opensphere that referenced this issue Jan 10, 2018
There was an inferred union type here {Array<!(ColumnDefinition\|FeatureTypeColumn)>} that the

compiler is not detecting as a mismatch with the declared type. I opened

google/closure-compiler#2783 with the compiler. This issue was causing

filters programmatically created from histogram bins to fail.
@brad4d
Copy link
Contributor

brad4d commented Jan 12, 2018

@shicks
I think I remember you saying recently that this is a known failing of OTI.
Am I remembering correctly?

@dimvar
Copy link
Contributor

dimvar commented Jan 16, 2018

The warning is produced properly on NTI. Is that still considered experimental or is it something that we should switch to?

NTI is not experimental anymore. You can switch to it.

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

No branches or pull requests

4 participants