-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Give a semantic error on with statements #176
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
Changes from all commits
8cbe88b
f79cba2
ed3d740
29284cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5284,7 +5284,7 @@ module ts { | |
|
||
function checkWithStatement(node: WithStatement) { | ||
checkExpression(node.expression); | ||
checkSourceElement(node.statement); | ||
error(node.expression, Diagnostics.All_symbols_within_a_with_block_will_be_resolved_to_any); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems wrong. The statement of the 'with' block should not be checked, but the expression of the with block should still be checked. Yes? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am open to discussing checking the expression, but as @RyanCavanaugh says, skipping it is consistent with the old compiler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. small tweak. can you just underline the 'while' token (i think you can get it with the scanner). it seems weird to underling the expression since you're complaining about the 'while' block. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Should be the |
||
} | ||
|
||
function checkSwitchStatement(node: SwitchStatement) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
==== tests/cases/compiler/functionExpressionInWithBlock.ts (1 errors) ==== | ||
function x() { | ||
with({}) { | ||
~~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
function f() { | ||
() => this; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts (1 errors) ==== | ||
==== tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode14.ts (2 errors) ==== | ||
"use strict"; | ||
with (a) { | ||
~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
~ | ||
!!! Cannot find name 'a'. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts (2 errors) ==== | ||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement1.d.ts (3 errors) ==== | ||
with (foo) { | ||
~~~~ | ||
!!! Statements are not allowed in ambient contexts. | ||
~~~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
~~~ | ||
!!! Cannot find name 'foo'. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
==== tests/cases/conformance/parser/ecmascript5/Statements/parserWithStatement2.ts (1 errors) ==== | ||
with (1) | ||
~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
return; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
==== tests/cases/compiler/sourceMapValidationStatements.ts (1 errors) ==== | ||
function f() { | ||
var y; | ||
var x = 0; | ||
for (var i = 0; i < 10; i++) { | ||
x += i; | ||
x *= 0; | ||
} | ||
if (x > 17) { | ||
x /= 9; | ||
} else { | ||
x += 10; | ||
x++; | ||
} | ||
var a = [ | ||
1, | ||
2, | ||
3 | ||
]; | ||
var obj = { | ||
z: 1, | ||
q: "hello" | ||
}; | ||
for (var j in a) { | ||
obj.z = a[j]; | ||
var v = 10; | ||
} | ||
try { | ||
obj.q = "ohhh"; | ||
} catch (e) { | ||
if (obj.z < 10) { | ||
obj.z = 12; | ||
} else { | ||
obj.q = "hmm"; | ||
} | ||
} | ||
try { | ||
throw new Error(); | ||
} catch (e1) { | ||
var b = e1; | ||
} finally { | ||
y = 70; | ||
} | ||
with (obj) { | ||
~~~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
i = 2; | ||
z = 10; | ||
} | ||
switch (obj.z) { | ||
case 0: { | ||
x++; | ||
break; | ||
|
||
} | ||
case 1: { | ||
x--; | ||
break; | ||
|
||
} | ||
default: { | ||
x *= 2; | ||
x = 50; | ||
break; | ||
|
||
} | ||
} | ||
while (x < 10) { | ||
x++; | ||
} | ||
do { | ||
x--; | ||
} while (x > 4) | ||
x = y; | ||
var z = (x == 1) ? x + 1 : x - 1; | ||
(x == 1) ? x + 1 : x - 1; | ||
x === 1; | ||
x = z = 40; | ||
eval("y"); | ||
return; | ||
} | ||
var b = function () { | ||
var x = 10; | ||
x = x + 1; | ||
}; | ||
f(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
==== tests/cases/compiler/withStatementNestedScope.ts (1 errors) ==== | ||
var x = 1; | ||
with (x) { | ||
~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
function f(a: number) { | ||
return 1; | ||
} | ||
// should be any | ||
var r = f(1); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
==== tests/cases/conformance/statements/withStatements/withStatements.ts (2 errors) ==== | ||
==== tests/cases/conformance/statements/withStatements/withStatements.ts (1 errors) ==== | ||
var x = 12; | ||
with (x) { | ||
~ | ||
!!! All symbols within a 'with' block will be resolved to 'any'. | ||
name = 'twelve' | ||
~~~~ | ||
!!! Cannot find name 'name'. | ||
id = 12 | ||
~~ | ||
!!! Cannot find name 'id'. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to talk about how we should still typecheck the expression (since there's no
with
craziness there) and how the error message is inaccurate (since symbolless expressions like3 > ''
ought to error anyway), but this is actually inline with the old compiler so I'm inclined to say it really doesn't matter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah we've always just thrown up our hands on everything in a 'with' block