~ohdeno/+junk/closure-compiler-svn-trunk

« back to all changes in this revision

Viewing changes to src/com/google/javascript/jscomp/TypeValidator.java

  • Committer: dimvar at google
  • Date: 2012-09-11 23:17:52 UTC
  • Revision ID: svn-v4:b0f006be-c8cd-11de-a2e8-8d36a3108c74:trunk:2184

Automated g4 rollback

*** Reason for rollback ***

Failures don't seem related to jscompiler. Resubmitting for now.

*** Original change description ***

Automated g4 rollback

*** Reason for rollback ***

Change caused tests to stop building.

*** Original change description ***

New @struct and @dict annotations for constructors.
With these annotations, one can enforce only dot or only bracket access on object properties.

R=nicksantos
DELTA=476  (391 added, 34 deleted, 51 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=5491

Show diffs side-by-side

added added

removed removed

Lines of Context:
117
117
  static final DiagnosticType UNKNOWN_TYPEOF_VALUE =
118
118
      DiagnosticType.warning("JSC_UNKNOWN_TYPEOF_VALUE", "unknown type: {0}");
119
119
 
 
120
  static final DiagnosticType ILLEGAL_PROPERTY_ACCESS =
 
121
      DiagnosticType.warning("JSC_ILLEGAL_PROPERTY_ACCESS",
 
122
                             "Cannot do {0} access on a {1}");
 
123
 
120
124
  static final DiagnosticGroup ALL_DIAGNOSTICS = new DiagnosticGroup(
121
125
      INVALID_CAST,
122
126
      TYPE_MISMATCH_WARNING,
125
129
      HIDDEN_PROPERTY_MISMATCH,
126
130
      INTERFACE_METHOD_NOT_IMPLEMENTED,
127
131
      HIDDEN_INTERFACE_PROPERTY_MISMATCH,
128
 
      UNKNOWN_TYPEOF_VALUE);
 
132
      UNKNOWN_TYPEOF_VALUE,
 
133
      ILLEGAL_PROPERTY_ACCESS);
129
134
 
130
135
  TypeValidator(AbstractCompiler compiler) {
131
136
    this.compiler = compiler;
315
320
   * @param indexType The type inside the brackets of the GETELEM.
316
321
   */
317
322
  void expectIndexMatch(NodeTraversal t, Node n, JSType objType,
318
 
      JSType indexType) {
 
323
                        JSType indexType) {
319
324
    Preconditions.checkState(n.isGetElem());
320
325
    Node indexNode = n.getLastChild();
 
326
    if (objType.isStruct()) {
 
327
      report(JSError.make(t.getSourceName(), indexNode,
 
328
                          ILLEGAL_PROPERTY_ACCESS, "'[]'", "struct"));
 
329
    }
321
330
    if (objType.isUnknownType()) {
322
331
      expectStringOrNumber(t, indexNode, indexType, "property access");
323
332
    } else {