Skip to content

isTypeOfExpression is broken #20875

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

Closed
tehwalris opened this issue Dec 23, 2017 · 2 comments
Closed

isTypeOfExpression is broken #20875

tehwalris opened this issue Dec 23, 2017 · 2 comments
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@tehwalris
Copy link
Contributor

TypeScript Version: 2.6.2
Code

import * as ts from 'typescript'

const testTypeOf = ts.createTypeOf(ts.createLiteral(""))
const testAwait = ts.createAwait(ts.createLiteral(""))

console.log(testTypeOf.kind, testAwait.kind) // 189, 191

console.log(ts.isTypeOfExpression(testTypeOf)) // Prints false, should be true
console.log(ts.isTypeOfExpression(testAwait)) // Prints true, should be false

Expected behavior:
ts.isTypeofExpression should return true (only) for TypeOfExpression nodes.

Actual behavior:
It returns true for AwaitExpression nodes instead.

Reason
The nodes both get created correctly (TypeOfExpression has kind 189 like it should), but the generated code for isTypeOfExpression uses the wrong number for kind: (from tsc.ts, starting on line 9132)

    function isTypeOfExpression(node) {
        return node.kind === 191;
    }
    ts.isTypeOfExpression = isTypeOfExpression;
    function isVoidExpression(node) {
        return node.kind === 190;
    }
    ts.isVoidExpression = isVoidExpression;
    function isAwaitExpression(node) {
        return node.kind === 191;
    }
    ts.isAwaitExpression = isAwaitExpression;

Note that some code uses the correct kind:

    function createTypeOf(expression) {
        var node = createSynthesizedNode(189);
        node.expression = ts.parenthesizePrefixOperand(expression);
        return node;
    }

Note that this issue also exists on master, even though the numbers for SyntaxKind enum values have changed.

I couldn't find where this code gets generated, so I haven't been able to investigate further.

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Dec 23, 2017
@DanielRosenwasser DanielRosenwasser added Good First Issue Well scoped, documented and has the green light Help Wanted You can do this labels Dec 23, 2017
@DanielRosenwasser
Copy link
Member

Since you've pinpointed the problem, we'd be open to a PR. 😃

@DanielRosenwasser DanielRosenwasser added the API Relates to the public API for TypeScript label Dec 23, 2017
tehwalris added a commit to tehwalris/TypeScript that referenced this issue Dec 24, 2017
@mhegazy mhegazy added this to the Community milestone Jan 4, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Jan 20, 2018
@mhegazy mhegazy modified the milestones: Community, TypeScript 2.7.1 Jan 20, 2018
errendir added a commit to errendir/TypeScript that referenced this issue Jan 20, 2018
* origin/master: (134 commits)
  Fix isTypeOfExpression in compiler API (microsoft#20875). (microsoft#20884)
  add completion filter for function like body (microsoft#21257)
  Make nonnull assertions and binding patterns apparent declared type locations (microsoft#20995)
  For `{ type: "a" } | { type: "b" }`, find references for the union property (microsoft#21298)
  configureNightly -> configurePrerelease
  Create a 'configure-insiders' and 'publish-insiders' task.
  Add createProgram on WatchCompilerHost
  in goToDefinition, use array helpers and clean up code (microsoft#21304)
  Support testing definition range of a reference gruop (microsoft#21302)
  Handle `undefined` input to firstDefined (microsoft#21300)
  Avoid spreading array (microsoft#21291)
  LEGO: check in for master to temporary branch.
  Accept new baselines
  Add regression test
  Properly handle contravariant inferences in inferReverseMappedType
  Remove unused properties from interface Refactor (microsoft#21286)
  LEGO: check in for master to temporary branch.
  Fold newline logic into getNewLineOrDefaultFromHost
  External test runner updates (microsoft#21276)
  Report more detailed info during script debug failure
  ...
@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
API Relates to the public API for TypeScript Bug A bug in TypeScript Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants