google / traceur-compiler

Traceur is a JavaScript.next-to-JavaScript-of-today compiler
Apache License 2.0
8.18k stars 580 forks source link

Type assertions should check all writes. #1494

Open arv opened 9 years ago

arv commented 9 years ago

Given:

var x: number;
x = 'hi';

This should generate a runtime type assertion error. However, we only add the asserts to variable declarations.

arv commented 9 years ago

@vojtajina @tpodom

tpodom commented 9 years ago

I'm thinking to do this we would need to keep a map of variable names to type annotation per scope. We could follow the block binding transformer for what the scopes are. Maybe we could refactor the core of that logic to reuse it in both transformers?

Do you think that sounds like the right track or am I missing something easier?

I think it's best not to assume the block binding has renamed in case the output language is es6.

On Nov 10, 2014, at 3:13 PM, Erik Arvidsson notifications@github.com wrote:

@vojtajina @tpodom

— Reply to this email directly or view it on GitHub.

arv commented 9 years ago

Take a look at the ScopeVisitor and related classes. The scope visitor builds up the scope tree so that will give you the map you need. The scope contains the original binding but now that I look it does not include possible type annotations. That would need to be added.

johnjbarton commented 9 years ago

Isn't trapping writes in expressions the more difficult part of the problem?