From 538e22a35eb515ade1fe0a944f305b8f0ae6b101 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 18 Apr 2016 13:51:51 -0700 Subject: [PATCH] Adding tests --- .../controlFlow/controlFlowIterationErrors.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts b/tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts index a8a580150e8..2e54b335537 100644 --- a/tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts +++ b/tests/cases/conformance/controlFlow/controlFlowIterationErrors.ts @@ -1,3 +1,5 @@ +// @noImplicitAny: true + let cond: boolean; function len(s: string) { @@ -46,3 +48,46 @@ function g2() { } x; } + +function asNumber(x: string | number): number { + return +x; +} + +function h1() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = +x + 1; + x; + } +} + +function h2() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x = asNumber(x) + 1; + x; + } +} + +function h3() { + let x: string | number | boolean; + x = "0"; + while (cond) { + let y = asNumber(x); + x = y + 1; + x; + } +} + +function h4() { + let x: string | number | boolean; + x = "0"; + while (cond) { + x; + let y = asNumber(x); + x = y + 1; + x; + } +}