6557752: Original type of an AST should be made available even if it is replaced with an ErrorType

Tue, 09 Sep 2008 10:28:21 -0700

author
jjg
date
Tue, 09 Sep 2008 10:28:21 -0700
changeset 110
91eea580fbe9
parent 107
5a9b808557b6
child 111
a92b756a888f

6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
Reviewed-by: mcimadamore

src/share/classes/com/sun/source/util/Trees.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/api/JavacTrees.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Symtab.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Type.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/code/Types.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Attr.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Check.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Enter.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Infer.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/comp/Resolve.java file | annotate | diff | comparison | revisions
src/share/classes/javax/lang/model/type/ErrorType.java file | annotate | diff | comparison | revisions
test/tools/javac/api/6557752/T6557752.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/source/util/Trees.java	Thu Sep 04 14:56:35 2008 -0700
     1.2 +++ b/src/share/classes/com/sun/source/util/Trees.java	Tue Sep 09 10:28:21 2008 -0700
     1.3 @@ -33,6 +33,7 @@
     1.4  import javax.lang.model.element.ExecutableElement;
     1.5  import javax.lang.model.element.TypeElement;
     1.6  import javax.lang.model.type.DeclaredType;
     1.7 +import javax.lang.model.type.ErrorType;
     1.8  import javax.lang.model.type.TypeMirror;
     1.9  import javax.tools.JavaCompiler.CompilationTask;
    1.10  
    1.11 @@ -177,4 +178,11 @@
    1.12       * @return true if {@code member} is accessible in {@code type}
    1.13       */
    1.14      public abstract boolean isAccessible(Scope scope, Element member, DeclaredType type);
    1.15 +
    1.16 +    /**
    1.17 +      * Gets the original type from the ErrorType object.
    1.18 +      * @param errorType The errorType for which we want to get the original type.
    1.19 +      * @returns javax.lang.model.type.TypeMirror corresponding to the original type, replaced by the ErrorType.
    1.20 +      */
    1.21 +    public abstract TypeMirror getOriginalType(ErrorType errorType);
    1.22  }
     2.1 --- a/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Thu Sep 04 14:56:35 2008 -0700
     2.2 +++ b/src/share/classes/com/sun/tools/javac/api/JavacTrees.java	Tue Sep 09 10:28:21 2008 -0700
     2.3 @@ -322,4 +322,18 @@
     2.4              return t2;
     2.5          }
     2.6      }
     2.7 +
     2.8 +    /**
     2.9 +     * Gets the original type from the ErrorType object.
    2.10 +     * @param errorType The errorType for which we want to get the original type.
    2.11 +     * @returns TypeMirror corresponding to the original type, replaced by the ErrorType.
    2.12 +     *          noType (type.tag == NONE) is returned if there is no original type.
    2.13 +     */
    2.14 +    public TypeMirror getOriginalType(javax.lang.model.type.ErrorType errorType) {
    2.15 +        if (errorType instanceof com.sun.tools.javac.code.Type.ErrorType) {
    2.16 +            return ((com.sun.tools.javac.code.Type.ErrorType)errorType).getOriginalType();
    2.17 +        }
    2.18 +
    2.19 +        return com.sun.tools.javac.code.Type.noType;
    2.20 +    }
    2.21  }
     3.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Sep 04 14:56:35 2008 -0700
     3.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Sep 09 10:28:21 2008 -0700
     3.3 @@ -776,7 +776,7 @@
     3.4              } catch (CompletionFailure ex) {
     3.5                  // quiet error recovery
     3.6                  flags_field |= (PUBLIC|STATIC);
     3.7 -                this.type = new ErrorType(this);
     3.8 +                this.type = new ErrorType(this, Type.noType);
     3.9                  throw ex;
    3.10              }
    3.11          }
     4.1 --- a/src/share/classes/com/sun/tools/javac/code/Symtab.java	Thu Sep 04 14:56:35 2008 -0700
     4.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Sep 09 10:28:21 2008 -0700
     4.3 @@ -93,8 +93,7 @@
     4.4       */
     4.5      public final ClassSymbol errSymbol;
     4.6  
     4.7 -    /** An instance of the error type.
     4.8 -     */
     4.9 +    /** A value for the errType, with a originalType of noType */
    4.10      public final Type errType;
    4.11  
    4.12      /** A value for the unknown type. */
    4.13 @@ -348,7 +347,7 @@
    4.14  
    4.15          // create the error symbols
    4.16          errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
    4.17 -        errType = new ErrorType(errSymbol);
    4.18 +        errType = new ErrorType(errSymbol, Type.noType);
    4.19  
    4.20          // initialize builtin types
    4.21          initType(byteType, "byte", "Byte");
    4.22 @@ -389,6 +388,9 @@
    4.23          scope.enter(booleanType.tsym);
    4.24          scope.enter(errType.tsym);
    4.25  
    4.26 +        // Enter symbol for the errSymbol
    4.27 +        scope.enter(errSymbol);
    4.28 +
    4.29          classes.put(predefClass.fullname, predefClass);
    4.30  
    4.31          reader = ClassReader.instance(context);
     5.1 --- a/src/share/classes/com/sun/tools/javac/code/Type.java	Thu Sep 04 14:56:35 2008 -0700
     5.2 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java	Tue Sep 09 10:28:21 2008 -0700
     5.3 @@ -1194,21 +1194,24 @@
     5.4      public static class ErrorType extends ClassType
     5.5              implements javax.lang.model.type.ErrorType {
     5.6  
     5.7 -        public ErrorType() {
     5.8 +        private Type originalType = null;
     5.9 +
    5.10 +        public ErrorType(Type originalType, TypeSymbol tsym) {
    5.11              super(noType, List.<Type>nil(), null);
    5.12              tag = ERROR;
    5.13 +            this.tsym = tsym;
    5.14 +            this.originalType = (originalType == null ? noType : originalType);
    5.15          }
    5.16  
    5.17 -        public ErrorType(ClassSymbol c) {
    5.18 -            this();
    5.19 -            tsym = c;
    5.20 +        public ErrorType(ClassSymbol c, Type originalType) {
    5.21 +            this(originalType, c);
    5.22              c.type = this;
    5.23              c.kind = ERR;
    5.24              c.members_field = new Scope.ErrorScope(c);
    5.25          }
    5.26  
    5.27 -        public ErrorType(Name name, TypeSymbol container) {
    5.28 -            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container));
    5.29 +        public ErrorType(Name name, TypeSymbol container, Type originalType) {
    5.30 +            this(new ClassSymbol(PUBLIC|STATIC|ACYCLIC, name, null, container), originalType);
    5.31          }
    5.32  
    5.33          @Override
    5.34 @@ -1234,6 +1237,10 @@
    5.35              return TypeKind.ERROR;
    5.36          }
    5.37  
    5.38 +        public Type getOriginalType() {
    5.39 +            return originalType;
    5.40 +        }
    5.41 +
    5.42          public <R, P> R accept(TypeVisitor<R, P> v, P p) {
    5.43              return v.visitError(this, p);
    5.44          }
     6.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java	Thu Sep 04 14:56:35 2008 -0700
     6.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Sep 09 10:28:21 2008 -0700
     6.3 @@ -2187,6 +2187,20 @@
     6.4          };
     6.5      // </editor-fold>
     6.6  
     6.7 +    // <editor-fold defaultstate="collapsed" desc="createErrorType">
     6.8 +    public Type createErrorType(Type originalType) {
     6.9 +        return new ErrorType(originalType, syms.errSymbol);
    6.10 +    }
    6.11 +
    6.12 +    public Type createErrorType(ClassSymbol c, Type originalType) {
    6.13 +        return new ErrorType(c, originalType);
    6.14 +    }
    6.15 +
    6.16 +    public Type createErrorType(Name name, TypeSymbol container, Type originalType) {
    6.17 +        return new ErrorType(name, container, originalType);
    6.18 +    }
    6.19 +    // </editor-fold>
    6.20 +
    6.21      // <editor-fold defaultstate="collapsed" desc="rank">
    6.22      /**
    6.23       * The rank of a class is the length of the longest path between
    6.24 @@ -2604,7 +2618,7 @@
    6.25                  if (!bound.isInterface())
    6.26                      classCount++;
    6.27              if (classCount > 1)
    6.28 -                return syms.errType;
    6.29 +                return createErrorType(t);
    6.30          }
    6.31          return makeCompoundType(bounds);
    6.32      }
     7.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java	Thu Sep 04 14:56:35 2008 -0700
     7.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java	Tue Sep 09 10:28:21 2008 -0700
     7.3 @@ -159,7 +159,7 @@
     7.4       *  If check succeeds, store type in tree and return it.
     7.5       *  If check fails, store errType in tree and return it.
     7.6       *  No checks are performed if the prototype is a method type.
     7.7 -     *  Its not necessary in this case since we know that kind and type
     7.8 +     *  It is not necessary in this case since we know that kind and type
     7.9       *  are correct.
    7.10       *
    7.11       *  @param tree     The tree whose kind and type is checked
    7.12 @@ -176,7 +176,7 @@
    7.13                  log.error(tree.pos(), "unexpected.type",
    7.14                            kindNames(pkind),
    7.15                            kindName(ownkind));
    7.16 -                owntype = syms.errType;
    7.17 +                owntype = types.createErrorType(owntype);
    7.18              }
    7.19          }
    7.20          tree.type = owntype;
    7.21 @@ -524,7 +524,7 @@
    7.22              // check that type variable is already visible
    7.23              if (t.getUpperBound() == null) {
    7.24                  log.error(tree.pos(), "illegal.forward.ref");
    7.25 -                return syms.errType;
    7.26 +                return types.createErrorType(t);
    7.27              }
    7.28          } else {
    7.29              t = chk.checkClassType(tree.pos(), t, checkExtensible|!allowGenerics);
    7.30 @@ -533,12 +533,12 @@
    7.31              log.error(tree.pos(), "intf.expected.here");
    7.32              // return errType is necessary since otherwise there might
    7.33              // be undetected cycles which cause attribution to loop
    7.34 -            return syms.errType;
    7.35 +            return types.createErrorType(t);
    7.36          } else if (checkExtensible &&
    7.37                     classExpected &&
    7.38                     (t.tsym.flags() & INTERFACE) != 0) {
    7.39              log.error(tree.pos(), "no.intf.expected.here");
    7.40 -            return syms.errType;
    7.41 +            return types.createErrorType(t);
    7.42          }
    7.43          if (checkExtensible &&
    7.44              ((t.tsym.flags() & FINAL) != 0)) {
    7.45 @@ -804,7 +804,7 @@
    7.46              Type base = types.asSuper(exprType, syms.iterableType.tsym);
    7.47              if (base == null) {
    7.48                  log.error(tree.expr.pos(), "foreach.not.applicable.to.type");
    7.49 -                elemtype = syms.errType;
    7.50 +                elemtype = types.createErrorType(exprType);
    7.51              } else {
    7.52                  List<Type> iterableParams = base.allparams();
    7.53                  elemtype = iterableParams.isEmpty()
    7.54 @@ -1219,7 +1219,7 @@
    7.55                  if (methName == names._super) {
    7.56                      if (site == syms.objectType) {
    7.57                          log.error(tree.meth.pos(), "no.superclass", site);
    7.58 -                        site = syms.errType;
    7.59 +                        site = types.createErrorType(syms.objectType);
    7.60                      } else {
    7.61                          site = types.supertype(site);
    7.62                      }
    7.63 @@ -1351,7 +1351,7 @@
    7.64          }
    7.65  
    7.66      public void visitNewClass(JCNewClass tree) {
    7.67 -        Type owntype = syms.errType;
    7.68 +        Type owntype = types.createErrorType(tree.type);
    7.69  
    7.70          // The local environment of a class creation is
    7.71          // a new environment nested in the current one.
    7.72 @@ -1551,7 +1551,7 @@
    7.73      }
    7.74  
    7.75      public void visitNewArray(JCNewArray tree) {
    7.76 -        Type owntype = syms.errType;
    7.77 +        Type owntype = types.createErrorType(tree.type);
    7.78          Type elemtype;
    7.79          if (tree.elemtype != null) {
    7.80              elemtype = attribType(tree.elemtype, env);
    7.81 @@ -1571,7 +1571,7 @@
    7.82                      log.error(tree.pos(), "illegal.initializer.for.type",
    7.83                                pt);
    7.84                  }
    7.85 -                elemtype = syms.errType;
    7.86 +                elemtype = types.createErrorType(pt);
    7.87              }
    7.88          }
    7.89          if (tree.elems != null) {
    7.90 @@ -1631,7 +1631,7 @@
    7.91          Symbol operator = tree.operator =
    7.92              rs.resolveUnaryOperator(tree.pos(), tree.getTag(), env, argtype);
    7.93  
    7.94 -        Type owntype = syms.errType;
    7.95 +        Type owntype = types.createErrorType(tree.type);
    7.96          if (operator.kind == MTH) {
    7.97              owntype = (JCTree.PREINC <= tree.getTag() && tree.getTag() <= JCTree.POSTDEC)
    7.98                  ? tree.arg.type
    7.99 @@ -1667,7 +1667,7 @@
   7.100          Symbol operator = tree.operator =
   7.101              rs.resolveBinaryOperator(tree.pos(), tree.getTag(), env, left, right);
   7.102  
   7.103 -        Type owntype = syms.errType;
   7.104 +        Type owntype = types.createErrorType(tree.type);
   7.105          if (operator.kind == MTH) {
   7.106              owntype = operator.type.getReturnType();
   7.107              int opc = chk.checkOperator(tree.lhs.pos(),
   7.108 @@ -1728,7 +1728,7 @@
   7.109      }
   7.110  
   7.111      public void visitIndexed(JCArrayAccess tree) {
   7.112 -        Type owntype = syms.errType;
   7.113 +        Type owntype = types.createErrorType(tree.type);
   7.114          Type atype = attribExpr(tree.indexed, env);
   7.115          attribExpr(tree.index, env, syms.intType);
   7.116          if (types.isArray(atype))
   7.117 @@ -1849,7 +1849,7 @@
   7.118                  elt = ((ArrayType)elt).elemtype;
   7.119              if (elt.tag == TYPEVAR) {
   7.120                  log.error(tree.pos(), "type.var.cant.be.deref");
   7.121 -                result = syms.errType;
   7.122 +                result = types.createErrorType(tree.type);
   7.123                  return;
   7.124              }
   7.125          }
   7.126 @@ -2009,7 +2009,7 @@
   7.127                  }
   7.128              case ERROR:
   7.129                  // preserve identifier names through errors
   7.130 -                return new ErrorType(name, site.tsym).tsym;
   7.131 +                return types.createErrorType(name, site.tsym, site).tsym;
   7.132              default:
   7.133                  // The qualifier expression is of a primitive type -- only
   7.134                  // .class is allowed for these.
   7.135 @@ -2059,7 +2059,7 @@
   7.136                       int pkind,
   7.137                       Type pt,
   7.138                       boolean useVarargs) {
   7.139 -            if (pt.isErroneous()) return syms.errType;
   7.140 +            if (pt.isErroneous()) return types.createErrorType(site);
   7.141              Type owntype; // The computed type of this identifier occurrence.
   7.142              switch (sym.kind) {
   7.143              case TYP:
   7.144 @@ -2129,7 +2129,7 @@
   7.145                      for (List<Type> l = env.info.tvars; l.nonEmpty(); l = l.tail)
   7.146                          if (!owntype.contains(l.head)) {
   7.147                              log.error(tree.pos(), "undetermined.type", owntype1);
   7.148 -                            owntype1 = syms.errType;
   7.149 +                            owntype1 = types.createErrorType(owntype1);
   7.150                          }
   7.151                      owntype = owntype1;
   7.152                  }
   7.153 @@ -2332,7 +2332,7 @@
   7.154                            "internal.error.cant.instantiate",
   7.155                            sym, site,
   7.156                            Type.toString(pt.getParameterTypes()));
   7.157 -            owntype = syms.errType;
   7.158 +            owntype = types.createErrorType(site);
   7.159          } else {
   7.160              // System.out.println("call   : " + env.tree);
   7.161              // System.out.println("method : " + owntype);
   7.162 @@ -2454,7 +2454,7 @@
   7.163       *  before supertype structure is completely known
   7.164       */
   7.165      public void visitTypeApply(JCTypeApply tree) {
   7.166 -        Type owntype = syms.errType;
   7.167 +        Type owntype = types.createErrorType(tree.type);
   7.168  
   7.169          // Attribute functor part of application and make sure it's a class.
   7.170          Type clazztype = chk.checkClassType(tree.clazz.pos(), attribType(tree.clazz, env));
   7.171 @@ -2498,7 +2498,7 @@
   7.172                  } else {
   7.173                      log.error(tree.pos(), "type.doesnt.take.params", clazztype.tsym);
   7.174                  }
   7.175 -                owntype = syms.errType;
   7.176 +                owntype = types.createErrorType(tree.type);
   7.177              }
   7.178          }
   7.179          result = check(tree, owntype, TYP, pkind, pt);
     8.1 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java	Thu Sep 04 14:56:35 2008 -0700
     8.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java	Tue Sep 09 10:28:21 2008 -0700
     8.3 @@ -192,12 +192,12 @@
     8.4      Type typeError(DiagnosticPosition pos, Object problem, Type found, Type req) {
     8.5          log.error(pos, "prob.found.req",
     8.6                    problem, found, req);
     8.7 -        return syms.errType;
     8.8 +        return types.createErrorType(found);
     8.9      }
    8.10  
    8.11      Type typeError(DiagnosticPosition pos, String problem, Type found, Type req, Object explanation) {
    8.12          log.error(pos, "prob.found.req.1", problem, found, req, explanation);
    8.13 -        return syms.errType;
    8.14 +        return types.createErrorType(found);
    8.15      }
    8.16  
    8.17      /** Report an error that wrong type tag was found.
    8.18 @@ -208,7 +208,7 @@
    8.19       */
    8.20      Type typeTagError(DiagnosticPosition pos, Object required, Object found) {
    8.21          log.error(pos, "type.found.req", found, required);
    8.22 -        return syms.errType;
    8.23 +        return types.createErrorType(found instanceof Type ? (Type)found : syms.errType);
    8.24      }
    8.25  
    8.26      /** Report an error that symbol cannot be referenced before super
    8.27 @@ -348,11 +348,11 @@
    8.28              return typeError(pos, diags.fragment("possible.loss.of.precision"), found, req);
    8.29          if (found.isSuperBound()) {
    8.30              log.error(pos, "assignment.from.super-bound", found);
    8.31 -            return syms.errType;
    8.32 +            return types.createErrorType(found);
    8.33          }
    8.34          if (req.isExtendsBound()) {
    8.35              log.error(pos, "assignment.to.extends-bound", req);
    8.36 -            return syms.errType;
    8.37 +            return types.createErrorType(found);
    8.38          }
    8.39          return typeError(pos, diags.fragment("incompatible.types"), found, req);
    8.40      }
    8.41 @@ -378,7 +378,7 @@
    8.42                      log.error(pos,
    8.43                                "undetermined.type" + (d!=null ? ".1" : ""),
    8.44                                t, d);
    8.45 -                    return syms.errType;
    8.46 +                    return types.createErrorType(pt);
    8.47                  } else {
    8.48                      JCDiagnostic d = ex.getDiagnostic();
    8.49                      return typeError(pos,
    8.50 @@ -469,7 +469,7 @@
    8.51      Type checkNonVoid(DiagnosticPosition pos, Type t) {
    8.52          if (t.tag == VOID) {
    8.53              log.error(pos, "void.not.allowed.here");
    8.54 -            return syms.errType;
    8.55 +            return types.createErrorType(t);
    8.56          } else {
    8.57              return t;
    8.58          }
    8.59 @@ -521,7 +521,7 @@
    8.60                                  t);
    8.61          } else if (!types.isReifiable(t)) {
    8.62              log.error(pos, "illegal.generic.type.for.instof");
    8.63 -            return syms.errType;
    8.64 +            return types.createErrorType(t);
    8.65          } else {
    8.66              return t;
    8.67          }
    8.68 @@ -1542,7 +1542,7 @@
    8.69              return;
    8.70          if (seen.contains(t)) {
    8.71              tv = (TypeVar)t;
    8.72 -            tv.bound = new ErrorType();
    8.73 +            tv.bound = types.createErrorType(t);
    8.74              log.error(pos, "cyclic.inheritance", t);
    8.75          } else if (t.tag == TYPEVAR) {
    8.76              tv = (TypeVar)t;
    8.77 @@ -1597,11 +1597,11 @@
    8.78      private void noteCyclic(DiagnosticPosition pos, ClassSymbol c) {
    8.79          log.error(pos, "cyclic.inheritance", c);
    8.80          for (List<Type> l=types.interfaces(c.type); l.nonEmpty(); l=l.tail)
    8.81 -            l.head = new ErrorType((ClassSymbol)l.head.tsym);
    8.82 +            l.head = types.createErrorType((ClassSymbol)l.head.tsym, Type.noType);
    8.83          Type st = types.supertype(c.type);
    8.84          if (st.tag == CLASS)
    8.85 -            ((ClassType)c.type).supertype_field = new ErrorType((ClassSymbol)st.tsym);
    8.86 -        c.type = new ErrorType(c);
    8.87 +            ((ClassType)c.type).supertype_field = types.createErrorType((ClassSymbol)st.tsym, Type.noType);
    8.88 +        c.type = types.createErrorType(c, c.type);
    8.89          c.flags_field |= ACYCLIC;
    8.90      }
    8.91  
     9.1 --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java	Thu Sep 04 14:56:35 2008 -0700
     9.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java	Tue Sep 09 10:28:21 2008 -0700
     9.3 @@ -98,6 +98,7 @@
     9.4      ClassReader reader;
     9.5      Annotate annotate;
     9.6      MemberEnter memberEnter;
     9.7 +    Types types;
     9.8      Lint lint;
     9.9      JavaFileManager fileManager;
    9.10  
    9.11 @@ -119,6 +120,7 @@
    9.12          syms = Symtab.instance(context);
    9.13          chk = Check.instance(context);
    9.14          memberEnter = MemberEnter.instance(context);
    9.15 +        types = Types.instance(context);
    9.16          annotate = Annotate.instance(context);
    9.17          lint = Lint.instance(context);
    9.18  
    9.19 @@ -355,7 +357,7 @@
    9.20          // Enter class into `compiled' table and enclosing scope.
    9.21          if (chk.compiled.get(c.flatname) != null) {
    9.22              duplicateClass(tree.pos(), c);
    9.23 -            result = new ErrorType(tree.name, (TypeSymbol)owner);
    9.24 +            result = types.createErrorType(tree.name, (TypeSymbol)owner, Type.noType);
    9.25              tree.sym = (ClassSymbol)result.tsym;
    9.26              return;
    9.27          }
    10.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Sep 04 14:56:35 2008 -0700
    10.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Sep 09 10:28:21 2008 -0700
    10.3 @@ -204,7 +204,7 @@
    10.4              return true;
    10.5          }
    10.6  
    10.7 -    /** Instaniate undetermined type variable to the lub of all its lower bounds.
    10.8 +    /** Instantiate undetermined type variable to the lub of all its lower bounds.
    10.9       *  Throw a NoInstanceException if this not possible.
   10.10       */
   10.11      void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
   10.12 @@ -216,7 +216,7 @@
   10.13              else {
   10.14                  that.inst = types.lub(that.lobounds);
   10.15              }
   10.16 -            if (that.inst == null || that.inst == syms.errType)
   10.17 +            if (that.inst == null || that.inst.tag == ERROR)
   10.18                      throw ambiguousNoInstanceException
   10.19                          .setMessage("no.unique.minimal.instance.exists",
   10.20                                      that.qtype, that.lobounds);
    11.1 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Thu Sep 04 14:56:35 2008 -0700
    11.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Sep 09 10:28:21 2008 -0700
    11.3 @@ -656,7 +656,7 @@
    11.4                      return new AmbiguityError(m1, m2);
    11.5                  // both abstract, neither overridden; merge throws clause and result type
    11.6                  Symbol result;
    11.7 -                Type result2 = mt2.getReturnType();;
    11.8 +                Type result2 = mt2.getReturnType();
    11.9                  if (mt2.tag == FORALL)
   11.10                      result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
   11.11                  if (types.isSubtype(mt1.getReturnType(), result2)) {
   11.12 @@ -1099,7 +1099,7 @@
   11.13              if (sym == syms.errSymbol // preserve the symbol name through errors
   11.14                  || ((sym.kind & ERRONEOUS) == 0 // make sure an error symbol is returned
   11.15                      && (sym.kind & TYP) != 0))
   11.16 -                sym = new ErrorType(name, qualified?site.tsym:syms.noSymbol).tsym;
   11.17 +                sym = types.createErrorType(name, qualified ? site.tsym : syms.noSymbol, sym.type).tsym;
   11.18          }
   11.19          return sym;
   11.20      }
    12.1 --- a/src/share/classes/javax/lang/model/type/ErrorType.java	Thu Sep 04 14:56:35 2008 -0700
    12.2 +++ b/src/share/classes/javax/lang/model/type/ErrorType.java	Tue Sep 09 10:28:21 2008 -0700
    12.3 @@ -25,10 +25,6 @@
    12.4  
    12.5  package javax.lang.model.type;
    12.6  
    12.7 -
    12.8 -import javax.lang.model.element.TypeElement;
    12.9 -
   12.10 -
   12.11  /**
   12.12   * Represents a class or interface type that cannot be properly modeled.
   12.13   * This may be the result of a processing error,
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/test/tools/javac/api/6557752/T6557752.java	Tue Sep 09 10:28:21 2008 -0700
    13.3 @@ -0,0 +1,133 @@
    13.4 +/*
    13.5 + * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
    13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 + *
    13.8 + * This code is free software; you can redistribute it and/or modify it
    13.9 + * under the terms of the GNU General Public License version 2 only, as
   13.10 + * published by the Free Software Foundation.
   13.11 + *
   13.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
   13.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.15 + * version 2 for more details (a copy is included in the LICENSE file that
   13.16 + * accompanied this code).
   13.17 + *
   13.18 + * You should have received a copy of the GNU General Public License version
   13.19 + * 2 along with this work; if not, write to the Free Software Foundation,
   13.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.21 + *
   13.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
   13.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
   13.24 + * have any questions.
   13.25 + */
   13.26 +
   13.27 +
   13.28 +/*
   13.29 + * @test
   13.30 + * @bug     6557752
   13.31 + * @summary Test for wrapping the original type in ErrorType.
   13.32 + * @library ../lib
   13.33 + * @compile T6557752.java
   13.34 + * @run main T6557752
   13.35 + */
   13.36 +
   13.37 +import com.sun.source.tree.AssignmentTree;
   13.38 +import com.sun.source.tree.CompilationUnitTree;
   13.39 +import com.sun.source.tree.MethodInvocationTree;
   13.40 +import com.sun.source.util.JavacTask;
   13.41 +import com.sun.source.util.TreePath;
   13.42 +import com.sun.source.util.TreePathScanner;
   13.43 +import com.sun.source.util.Trees;
   13.44 +import com.sun.tools.javac.api.JavacTaskImpl;
   13.45 +import com.sun.tools.javac.util.List;
   13.46 +import java.io.IOException;
   13.47 +import java.net.URI;
   13.48 +import javax.lang.model.type.ErrorType;
   13.49 +import javax.lang.model.type.TypeKind;
   13.50 +import javax.lang.model.type.TypeMirror;
   13.51 +import javax.tools.JavaCompiler;
   13.52 +import javax.tools.JavaFileObject;
   13.53 +import javax.tools.SimpleJavaFileObject;
   13.54 +import javax.tools.ToolProvider;
   13.55 +import javax.lang.model.util.Types;
   13.56 +
   13.57 +public class T6557752 {
   13.58 +    static class MyFileObject extends SimpleJavaFileObject {
   13.59 +        public MyFileObject() {
   13.60 +            super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE);
   13.61 +        }
   13.62 +        public CharSequence getCharContent(boolean ignoreEncodingErrors) {
   13.63 +            return "import java.util.*;\n"
   13.64 +                + "public class Test {\n"
   13.65 +                + "    void foobar() {\n"
   13.66 +                + "        Iterator<Number> itr = null;\n"
   13.67 +                + "        String str = itr.next();\n"
   13.68 +                + "        FooBar fooBar = FooBar.foobar();\n"
   13.69 +                + "    }\n"
   13.70 +                + "}";
   13.71 +        }
   13.72 +    }
   13.73 +    static Trees trees;
   13.74 +    static JavacTask task = null;
   13.75 +    public static void main(String[] args) throws IOException {
   13.76 +        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
   13.77 +        task = (JavacTask) compiler.getTask(null, null, null, null, null, List.of(new MyFileObject()));
   13.78 +        Iterable<? extends CompilationUnitTree> asts = task.parse();
   13.79 +        task.analyze();
   13.80 +        trees = Trees.instance(task);
   13.81 +        MyVisitor myVisitor = new MyVisitor();
   13.82 +        for (CompilationUnitTree ast : asts) {
   13.83 +            myVisitor.compilationUnit = ast;
   13.84 +            myVisitor.scan(ast, null);
   13.85 +        }
   13.86 +
   13.87 +        if (!myVisitor.foundError) {
   13.88 +            throw new AssertionError("Expected error not found!");
   13.89 +        }
   13.90 +    }
   13.91 +
   13.92 +    static class MyVisitor extends TreePathScanner<Void,Void> {
   13.93 +        public boolean foundError = false;
   13.94 +        CompilationUnitTree compilationUnit = null;
   13.95 +        int i = 0;
   13.96 +        @Override
   13.97 +        public Void visitMethodInvocation(MethodInvocationTree node, Void ignored) {
   13.98 +            TreePath path = TreePath.getPath(compilationUnit, node);
   13.99 +            TypeMirror typeMirror = trees.getTypeMirror(path);
  13.100 +            if (typeMirror.getKind() == TypeKind.ERROR) {
  13.101 +              if (i == 0) {
  13.102 +                String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
  13.103 +                if (!str1.equals("java.lang.Number")) {
  13.104 +                    throw new AssertionError("Trees.getOriginalType() error!");
  13.105 +                }
  13.106 +
  13.107 +                Types types = task.getTypes();
  13.108 +
  13.109 +                str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString();
  13.110 +                if (!str1.equals("java.lang.Number")) {
  13.111 +                    throw new AssertionError("Types.asElement() error!");
  13.112 +                }
  13.113 +
  13.114 +                i++;
  13.115 +              }
  13.116 +              else if (i == 1) {
  13.117 +                String str1 = trees.getOriginalType((ErrorType)typeMirror).toString();
  13.118 +                if (!str1.equals("FooBar")) {
  13.119 +                    throw new AssertionError("Trees.getOriginalType() error!");
  13.120 +                }
  13.121 +
  13.122 +                Types types = task.getTypes();
  13.123 +
  13.124 +                if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) {
  13.125 +                    throw new AssertionError("Ttypes.asElement() error!");
  13.126 +                }
  13.127 +                foundError = true;
  13.128 +              }
  13.129 +            }
  13.130 +
  13.131 +
  13.132 +            return null;
  13.133 +        }
  13.134 +
  13.135 +    }
  13.136 +}

mercurial