copy.Ident(tree, name.toTypeName()),
copy.Ident(tree, name).setSymbol(sym.type().resultType().symbol()),
    Tree adapt(Tree tree, int mode, Type pt) {	//new TextTreePrinter().print(tree).print(" adapt " + pt).println().end();//DEBUG	switch (tree.type) {	case OverloadedType(Symbol[] alts, Type[] alttypes):	    // resolve overloading	    if ((mode & FUNmode) == 0) {		try {		    infer.exprAlternative(tree, alts, alttypes, pt);		} catch (Type.Error ex) {		    error(tree.pos, ex.msg);		}		switch (tree.type) {		case OverloadedType(_, _):		    // overload resolution failed bcs no alternative matched prototype.		    typeError(tree.pos, tree.type, pt);		    tree.setSymbol(Symbol.ERROR).setType(Type.ErrorType);		    break;		default:		    return adapt(tree, mode, pt);		}	    }	    break;	case PolyType(Symbol[] tparams, Type restp):	    // apply parameterless functions	    // instantiate polymorphic expressions	    if (tparams.length == 0) {		return adapt(tree.setType(restp), mode, pt);	    } else if ((mode & (FUNmode | POLYmode)) == 0) {		try {		    tree = infer.exprInstance(tree, tparams, restp, pt);		} catch (Type.Error ex) {		    tree = error(tree.pos, ex.msg);		}		return adapt(tree, mode, pt);	    }	    break;	    	case MethodType(_, _):	    // convert unapplied methods to functions.	    if ((mode & (EXPRmode | FUNmode)) == EXPRmode && 		infer.isCompatible(tree.type, pt)) {		checkEtaExpandable(tree.pos, tree.type);		return transform(desugarize.etaExpand(tree, tree.type), mode, pt);	    } else if ((mode & (CONSTRmode | FUNmode)) == CONSTRmode) {		return error(tree.pos, "missing arguments for class constructor");	    }	}	if ((mode & PATTERNmode) != 0) {	    if (tree.isType()) {		Symbol clazz = tree.type.unalias().symbol();		if (clazz.isCaseClass()) {		    // set type to instantiated case class constructor		    tree.type = clazz.constructor().type();		    switch (tree.type) {		    case PolyType(Symbol[] tparams, Type restp):			try {			    infer.constructorInstance(tree, tparams, restp, pt);			} catch (Type.Error ex) {			    if (pt != Type.ErrorType) error(tree.pos, ex.msg);			    return tree.setType(Type.ErrorType);			}			if (!(tree.type instanceof Type.MethodType))			    tree = make.Apply(tree.pos, tree, Tree.EMPTY_ARRAY)				.setType(tree.type);		    }		} else if (clazz.isSubClass(definitions.SEQ_CLASS)) {		    // set type to instantiated sequence class constructor		    Type seqtp = dropVarArgs(pt.baseType(clazz));		    if (seqtp != Type.NoType) {			tree.type = seqConstructorType(seqtp, pt);		    } else {			error(tree.pos, "expected pattern type " + pt + 			      " does not conform to sequence " + clazz);		    }		} else if (tree.type != Type.ErrorType) {		    error(tree.pos, tree.type.symbol() + 			  " is neither a case class constructor nor a sequence class constructor");		}	    } 	    if ((mode & FUNmode) != 0) {		return tree;	    } else {		Symbol sym = tree.symbol();		// convert nullary case methods to types		// check that other idents or selects are stable.		switch (tree) {		case Ident(Name name):		    if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0)			return transform(			    make.Apply(				tree.pos, 				copy.Ident(tree, name.toTypeName()), 				Tree.EMPTY_ARRAY), 			    mode, pt);		    else 			checkStable(tree);		    break;		case Select(Tree qual, Name name):		    if (sym != null && isNullaryMethod(sym) && (sym.flags & CASE) != 0)			return transform(			    make.Apply(				tree.pos, 				copy.Select(tree, qual, name.toTypeName()), 				Tree.EMPTY_ARRAY), 			    mode, pt);		    else			checkStable(tree);		}	    }	} else if ((mode & EXPRmode) != 0) {	    if ((mode & FUNmode) != 0) {		if (tree.type.isObjectType()) {		    // insert apply method		    Symbol applyMeth = tree.type.lookup(Names.apply);		    if (applyMeth != Symbol.NONE && isAccessible(applyMeth, tree)) {			applyMeth.flags |= (ACCESSED | SELECTOR);			tree = make.Select(tree.pos, tree, Names.apply)			    .setSymbol(applyMeth)			    .setType(tree.type.memberType(applyMeth));			return adapt(tree, mode, pt);		    }		}	    } else if ((mode & QUALmode) == 0) {		// check that packages and static modules are not used as values		Symbol sym = tree.symbol();		if (sym != null && sym.kind != ERROR && !sym.isValue() &&		    tree.isTerm()) {		    error(tree.pos, tree.symbol() + " is not a value");		}	    }	}	Type owntype = tree.type;	if ((mode & (CONSTRmode | FUNmode)) == (CONSTRmode)) 	    owntype = owntype.instanceType();	if (!(owntype instanceof Type.PolyType || owntype.isSubType(pt))) {	    typeError(tree.pos, owntype, pt);	    explainTypes(owntype, pt);	    tree.type = Type.ErrorType;	}	return tree;    }