use of com.sun.tools.javac.code.Scope.DelegatedScope in project ceylon-compiler by ceylon.
the class Attr method visitLetExpr.
/* Added for Ceylon, required by the ExpressionTransformer */
@Override
public void visitLetExpr(LetExpr tree) {
Scope scope;
if (env.info.scope.owner.kind == Kinds.VAR) {
// for field initialisers we must access the parent scope, otherwise we get
// a DelegateScope which doesn't allow us to declare new variables
scope = env.info.scope.next;
} else
scope = env.info.scope;
if (scope instanceof DelegatedScope) {
throw new AssertionError("Broken use of LetExpr");
}
// make a new environment which captures the current one
Env<AttrContext> localEnv = env.dup(tree, env.info.dup(scope.dup()));
// Field initialisers have not been entered yet, so we need to do it now:
if (localEnv.info.scope.owner.kind == Kinds.TYP) {
memberEnter.memberEnter(tree, localEnv);
annotate.flush();
}
// find the lint
Env<AttrContext> lintEnv = env;
while (lintEnv.info.lint == null) lintEnv = lintEnv.next;
// Having found the enclosing lint value, we can initialize the lint value for this let
localEnv.info.lint = lintEnv.info.lint;
Lint prevLint = chk.setLint(env.info.lint);
try {
// do statements if we have any
if (tree.stats != null) {
if (sourceLanguage.isCeylon())
completeLocalTypes(tree.stats, localEnv);
attribStats(tree.stats, localEnv);
}
// now attribute the expression with the LET expected type (pt)
attribExpr(tree.expr, localEnv, pt);
// the type of the LET is the type of the expression
tree.type = tree.expr.type;
// same code in TransTypes.visit(LetExpr)
if (tree.type.constValue() != null && tree.stats != null && !tree.stats.isEmpty())
tree.type = tree.type.baseType();
} finally {
// exit the LET scope
localEnv.info.scope.leave();
// restore the previous lint
chk.setLint(prevLint);
}
}
Aggregations