JET-81 Assertion fails when processing in self-referring anonymous objects

This commit is contained in:
Andrey Breslav
2011-06-03 17:11:27 +04:00
parent 2446179949
commit 2350a8a731
2 changed files with 37 additions and 6 deletions
@@ -732,13 +732,22 @@ public class JetTypeInferrer {
}
@Override
public void visitObjectLiteralExpression(JetObjectLiteralExpression expression) {
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, trace);
public void visitObjectLiteralExpression(final JetObjectLiteralExpression expression) {
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices, new BindingTraceAdapter(trace) {
@Override
public void recordDeclarationResolution(@NotNull PsiElement declaration, @NotNull DeclarationDescriptor descriptor) {
if (declaration == expression.getObjectDeclaration()) {
JetType defaultType = ((ClassDescriptor) descriptor).getDefaultType();
result = defaultType;
if (!trace.isProcessed(expression)) {
recordExpressionType(expression, defaultType);
markAsProcessed(expression);
}
}
super.recordDeclarationResolution(declaration, descriptor);
}
});
topDownAnalyzer.processObject(scope, scope.getContainingDeclaration(), expression.getObjectDeclaration());
ClassDescriptor classDescriptor = trace.getBindingContext().getClassDescriptor(expression.getObjectDeclaration());
if (classDescriptor != null) {
result = classDescriptor.getDefaultType();
}
}
@Override
@@ -0,0 +1,22 @@
// JET-81 Assertion fails when processing self-referring anonymous objects
val y = object {
val a = y;
}
val z = y.a;
object A {
val x = A
}
val a = object {
{
b + 1
}
val x = <error>b</error>
val y = 1
}
val b = a.x
val c = a.y