HoriSun / closure-compiler

Automatically exported from code.google.com/p/closure-compiler
0 stars 0 forks source link

Const extern not respected #1219

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile with the following extern:
/** @const */ var FOO;
and the following code:
FOO = 1;
FOO = 2;

What is the expected output? What do you see instead?
Warning about assignment to const (x2)
Instead get no warnings at all.

What version of the product are you using? On what operating system?
jscomp-debug

Please provide any additional information below.
If the const definition is moved from the externs to the code, get warning on 
second asssignment (as expected).

Original issue reported on code.google.com by ndkrem...@google.com on 30 Jan 2014 at 5:10

GoogleCodeExporter commented 9 years ago

Original comment by tbreisac...@google.com on 16 Feb 2014 at 3:05

GoogleCodeExporter commented 9 years ago
Question: If we have "/** @const */ var FOO;" in the externs, should that mean:

1. FOO is not only declared externally, but also given a value, or
2. FOO is declared externally, but may not have a value yet, so it's okay to 
assign to it in the non-externs code.
?

If we choose option 1, then just writing "FOO = 1;" would be an error. If we 
choose option 2, then "FOO = 1;" on its own would be okay, but "FOO = 1; FOO = 
2;" would be an error. I would lean toward option 1.

Original comment by tbreisac...@google.com on 18 Feb 2014 at 7:11

GoogleCodeExporter commented 9 years ago
I would also lean toward option 1. Some constants are not known at compile 
time, but are still known to never change.

Original comment by blic...@google.com on 18 Feb 2014 at 7:32

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 8f5bc28d124b.

Original comment by blic...@google.com on 21 Feb 2014 at 6:56