ErrorHandler moved to BindingTrace
This commit is contained in:
@@ -10,23 +10,21 @@ import org.jetbrains.jet.lang.types.*;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class JetSemanticServices {
|
public class JetSemanticServices {
|
||||||
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
|
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary) {
|
||||||
return new JetSemanticServices(standardLibrary, errorHandler);
|
return new JetSemanticServices(standardLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JetSemanticServices createSemanticServices(Project project, ErrorHandler errorHandler) {
|
public static JetSemanticServices createSemanticServices(Project project) {
|
||||||
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project), errorHandler);
|
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final JetStandardLibrary standardLibrary;
|
private final JetStandardLibrary standardLibrary;
|
||||||
private final JetTypeChecker typeChecker;
|
private final JetTypeChecker typeChecker;
|
||||||
private final OverloadResolver overloadResolver;
|
private final OverloadResolver overloadResolver;
|
||||||
|
|
||||||
private final ErrorHandler errorHandler;
|
|
||||||
|
|
||||||
private JetSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
|
private JetSemanticServices(JetStandardLibrary standardLibrary) {
|
||||||
this.standardLibrary = standardLibrary;
|
this.standardLibrary = standardLibrary;
|
||||||
this.errorHandler = errorHandler;
|
|
||||||
this.typeChecker = new JetTypeChecker(standardLibrary);
|
this.typeChecker = new JetTypeChecker(standardLibrary);
|
||||||
this.overloadResolver = new OverloadResolver(typeChecker);
|
this.overloadResolver = new OverloadResolver(typeChecker);
|
||||||
}
|
}
|
||||||
@@ -46,11 +44,11 @@ public class JetSemanticServices {
|
|||||||
return new JetTypeInferrer(trace, flowInformationProvider, this);
|
return new JetTypeInferrer(trace, flowInformationProvider, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
// @NotNull
|
||||||
public ErrorHandler getErrorHandler() {
|
// public ErrorHandler getErrorHandler() {
|
||||||
return errorHandler;
|
// return errorHandler;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@NotNull
|
@NotNull
|
||||||
public JetTypeChecker getTypeChecker() {
|
public JetTypeChecker getTypeChecker() {
|
||||||
return typeChecker;
|
return typeChecker;
|
||||||
@@ -61,13 +59,4 @@ public class JetSemanticServices {
|
|||||||
return overloadResolver;
|
return overloadResolver;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public WritableScope createWritableScope(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner) {
|
|
||||||
return new WritableScopeImpl(scope, owner, errorHandler, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public WritableScope createWritableScope(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull DeclarationDescriptorVisitor<?, ? super WritableScope> modificationListener) {
|
|
||||||
return new WritableScopeImpl(scope, owner, errorHandler, modificationListener);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import com.intellij.psi.util.PsiUtilBase;
|
|||||||
import com.intellij.ui.awt.RelativePoint;
|
import com.intellij.ui.awt.RelativePoint;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.PsiNavigateUtil;
|
import com.intellij.util.PsiNavigateUtil;
|
||||||
import org.jetbrains.jet.lang.ErrorHandler;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
@@ -44,12 +43,12 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
|||||||
|
|
||||||
JetFile file = PsiTreeUtil.getParentOfType(element, JetFile.class);
|
JetFile file = PsiTreeUtil.getParentOfType(element, JetFile.class);
|
||||||
assert file != null;
|
assert file != null;
|
||||||
final BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, ErrorHandler.DO_NOTHING);
|
final BindingContext bindingContext = AnalyzingUtils.analyzeFile(file);
|
||||||
FunctionDescriptor functionDescriptor = bindingContext.getFunctionDescriptor(jetFunction);
|
FunctionDescriptor functionDescriptor = bindingContext.getFunctionDescriptor(jetFunction);
|
||||||
final Set<? extends FunctionDescriptor> overriddenFunctions = functionDescriptor.getOverriddenFunctions();
|
final Set<? extends FunctionDescriptor> overriddenFunctions = functionDescriptor.getOverriddenFunctions();
|
||||||
if (!overriddenFunctions.isEmpty()) {
|
if (!overriddenFunctions.isEmpty()) {
|
||||||
return new LineMarkerInfo<JetFunction>(
|
return new LineMarkerInfo<JetFunction>(
|
||||||
jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL,
|
jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL,
|
||||||
new Function<JetFunction, String>() {
|
new Function<JetFunction, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String fun(JetFunction jetFunction) {
|
public String fun(JetFunction jetFunction) {
|
||||||
@@ -66,32 +65,30 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
|||||||
}
|
}
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
String myEmptyText = "empty text";
|
String myEmptyText = "empty text";
|
||||||
if (myEmptyText != null) {
|
|
||||||
final JComponent renderer = HintUtil.createErrorLabel(myEmptyText);
|
final JComponent renderer = HintUtil.createErrorLabel(myEmptyText);
|
||||||
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
|
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
popup.show(new RelativePoint(event));
|
popup.show(new RelativePoint(event));
|
||||||
}
|
}
|
||||||
}
|
return;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
if (list.size() == 1) {
|
if (list.size() == 1) {
|
||||||
PsiNavigateUtil.navigate(list.iterator().next());
|
PsiNavigateUtil.navigate(list.iterator().next());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() {
|
final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() {
|
||||||
@Override
|
@Override
|
||||||
public String getElementText(PsiElement element) {
|
public String getElementText(PsiElement element) {
|
||||||
if (element instanceof JetFunction) {
|
if (element instanceof JetFunction) {
|
||||||
JetFunction function = (JetFunction) element;
|
JetFunction function = (JetFunction) element;
|
||||||
return bindingContext.getFunctionDescriptor(function).toString();
|
return bindingContext.getFunctionDescriptor(function).toString();
|
||||||
}
|
}
|
||||||
return super.getElementText(element);
|
return super.getElementText(element);
|
||||||
}
|
}
|
||||||
}, "title");
|
}, "title");
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
popup.show(new RelativePoint(event));
|
popup.show(new RelativePoint(event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,11 +75,11 @@ public class JetControlFlowProcessor {
|
|||||||
private JetElement resolveLabel(@NotNull String labelName, @NotNull JetSimpleNameExpression labelExpression) {
|
private JetElement resolveLabel(@NotNull String labelName, @NotNull JetSimpleNameExpression labelExpression) {
|
||||||
Stack<JetElement> stack = labeledElements.get(labelName);
|
Stack<JetElement> stack = labeledElements.get(labelName);
|
||||||
if (stack == null || stack.isEmpty()) {
|
if (stack == null || stack.isEmpty()) {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(labelExpression);
|
trace.getErrorHandler().unresolvedReference(labelExpression);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else if (stack.size() > 1) {
|
else if (stack.size() > 1) {
|
||||||
semanticServices.getErrorHandler().genericWarning(labelExpression.getNode(), "There is more than one label with such a name in this scope");
|
trace.getErrorHandler().genericWarning(labelExpression.getNode(), "There is more than one label with such a name in this scope");
|
||||||
}
|
}
|
||||||
|
|
||||||
JetElement result = stack.peek();
|
JetElement result = stack.peek();
|
||||||
@@ -417,14 +417,14 @@ public class JetControlFlowProcessor {
|
|||||||
assert targetLabel != null;
|
assert targetLabel != null;
|
||||||
loop = resolveLabel(labelName, targetLabel);
|
loop = resolveLabel(labelName, targetLabel);
|
||||||
if (!isLoop(loop)) {
|
if (!isLoop(loop)) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "The label '" + targetLabel.getText() + "' does not denote a loop");
|
trace.getErrorHandler().genericError(expression.getNode(), "The label '" + targetLabel.getText() + "' does not denote a loop");
|
||||||
loop = null;
|
loop = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loop = builder.getCurrentLoop();
|
loop = builder.getCurrentLoop();
|
||||||
if (loop == null) {
|
if (loop == null) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "'break' and 'continue' are only allowed inside a loop");
|
trace.getErrorHandler().genericError(expression.getNode(), "'break' and 'continue' are only allowed inside a loop");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loop;
|
return loop;
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ public class AnalyzingUtils {
|
|||||||
Project project = namespace.getProject();
|
Project project = namespace.getProject();
|
||||||
|
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project, bindingTraceContext.getErrorHandler());
|
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||||
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, semanticServices, bindingTraceContext);
|
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, semanticServices, bindingTraceContext);
|
||||||
|
|
||||||
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
|
||||||
WritableScope scope = semanticServices.createWritableScope(libraryScope, new ModuleDescriptor("<module>"));
|
WritableScope scope = new WritableScopeImpl(libraryScope, new ModuleDescriptor("<module>"), bindingTraceContext.getErrorHandler(), null);
|
||||||
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
|
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
|
||||||
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
|
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
|
||||||
scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class ClassDescriptorResolver {
|
|||||||
|
|
||||||
trace.recordDeclarationResolution(classElement, classDescriptor);
|
trace.recordDeclarationResolution(classElement, classDescriptor);
|
||||||
|
|
||||||
WritableScope parameterScope = semanticServices.createWritableScope(scope, classDescriptor);
|
WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler(), null);
|
||||||
|
|
||||||
// This call has side-effects on the parameterScope (fills it in)
|
// This call has side-effects on the parameterScope (fills it in)
|
||||||
List<TypeParameterDescriptor> typeParameters
|
List<TypeParameterDescriptor> typeParameters
|
||||||
@@ -124,7 +124,7 @@ public class ClassDescriptorResolver {
|
|||||||
final JetScope typeParameterScope,
|
final JetScope typeParameterScope,
|
||||||
final Collection<? extends JetType> supertypes) {
|
final Collection<? extends JetType> supertypes) {
|
||||||
|
|
||||||
final WritableScope memberDeclarations = semanticServices.createWritableScope(typeParameterScope, classDescriptor);
|
final WritableScope memberDeclarations = new WritableScopeImpl(typeParameterScope, classDescriptor, trace.getErrorHandler(), null);
|
||||||
|
|
||||||
List<JetDeclaration> declarations = classElement.getDeclarations();
|
List<JetDeclaration> declarations = classElement.getDeclarations();
|
||||||
for (JetDeclaration declaration : declarations) {
|
for (JetDeclaration declaration : declarations) {
|
||||||
@@ -166,7 +166,7 @@ public class ClassDescriptorResolver {
|
|||||||
AnnotationResolver.INSTANCE.resolveAnnotations(function.getModifierList()),
|
AnnotationResolver.INSTANCE.resolveAnnotations(function.getModifierList()),
|
||||||
JetPsiUtil.safeName(function.getName())
|
JetPsiUtil.safeName(function.getName())
|
||||||
);
|
);
|
||||||
WritableScope innerScope = semanticServices.createWritableScope(scope, functionDescriptor);
|
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler(), null);
|
||||||
innerScope.addLabeledDeclaration(functionDescriptor);
|
innerScope.addLabeledDeclaration(functionDescriptor);
|
||||||
|
|
||||||
// The two calls below have side-effects on parameterScope
|
// The two calls below have side-effects on parameterScope
|
||||||
@@ -197,12 +197,12 @@ public class ClassDescriptorResolver {
|
|||||||
|
|
||||||
ASTNode valOrVarNode = valueParameter.getValOrVarNode();
|
ASTNode valOrVarNode = valueParameter.getValOrVarNode();
|
||||||
if (valueParameter.isRef() && valOrVarNode != null) {
|
if (valueParameter.isRef() && valOrVarNode != null) {
|
||||||
semanticServices.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
|
trace.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType type;
|
JetType type;
|
||||||
if (typeReference == null) {
|
if (typeReference == null) {
|
||||||
semanticServices.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
|
trace.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
|
||||||
type = ErrorUtils.createErrorType("Type annotation was missing");
|
type = ErrorUtils.createErrorType("Type annotation was missing");
|
||||||
} else {
|
} else {
|
||||||
type = typeResolver.resolveType(parameterScope, typeReference);
|
type = typeResolver.resolveType(parameterScope, typeReference);
|
||||||
@@ -359,7 +359,7 @@ public class ClassDescriptorResolver {
|
|||||||
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
JetPropertyAccessor setter = property.getSetter();
|
JetPropertyAccessor setter = property.getSetter();
|
||||||
if (setter != null && !property.isVar()) {
|
if (setter != null && !property.isVar()) {
|
||||||
semanticServices.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
|
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
PropertySetterDescriptor setterDescriptor = null;
|
PropertySetterDescriptor setterDescriptor = null;
|
||||||
@@ -370,13 +370,13 @@ public class ClassDescriptorResolver {
|
|||||||
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, annotations, setter.getBodyExpression() != null);
|
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, annotations, setter.getBodyExpression() != null);
|
||||||
if (parameter != null) {
|
if (parameter != null) {
|
||||||
if (parameter.isRef()) {
|
if (parameter.isRef()) {
|
||||||
semanticServices.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
|
trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
|
||||||
}
|
}
|
||||||
|
|
||||||
// This check is redundant: the parser does not allow a default value, but we'll keep it just in case
|
// This check is redundant: the parser does not allow a default value, but we'll keep it just in case
|
||||||
JetExpression defaultValue = parameter.getDefaultValue();
|
JetExpression defaultValue = parameter.getDefaultValue();
|
||||||
if (defaultValue != null) {
|
if (defaultValue != null) {
|
||||||
semanticServices.getErrorHandler().genericError(defaultValue.getNode(), "Setter parameters can not have default values");
|
trace.getErrorHandler().genericError(defaultValue.getNode(), "Setter parameters can not have default values");
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType type;
|
JetType type;
|
||||||
@@ -389,7 +389,7 @@ public class ClassDescriptorResolver {
|
|||||||
JetType inType = propertyDescriptor.getInType();
|
JetType inType = propertyDescriptor.getInType();
|
||||||
if (inType != null) {
|
if (inType != null) {
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(type, inType)) {
|
if (!semanticServices.getTypeChecker().isSubtypeOf(type, inType)) {
|
||||||
semanticServices.getErrorHandler().genericError(typeReference.getNode(), "Setter parameter type must be a subtype of the type of the property, i.e. " + inType);
|
trace.getErrorHandler().genericError(typeReference.getNode(), "Setter parameter type must be a subtype of the type of the property, i.e. " + inType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -433,7 +433,7 @@ public class ClassDescriptorResolver {
|
|||||||
if (propertyTypeRef == null) {
|
if (propertyTypeRef == null) {
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (initializer == null) {
|
if (initializer == null) {
|
||||||
semanticServices.getErrorHandler().genericError(property.getNode(), "This property must either have a type annotation or be initialized");
|
trace.getErrorHandler().genericError(property.getNode(), "This property must either have a type annotation or be initialized");
|
||||||
type = ErrorUtils.createErrorType("No type, no body");
|
type = ErrorUtils.createErrorType("No type, no body");
|
||||||
} else {
|
} else {
|
||||||
// TODO : ??? Fix-point here: what if we have something like "val a = foo {a.bar()}"
|
// TODO : ??? Fix-point here: what if we have something like "val a = foo {a.bar()}"
|
||||||
@@ -467,7 +467,7 @@ public class ClassDescriptorResolver {
|
|||||||
return constructorDescriptor.initialize(
|
return constructorDescriptor.initialize(
|
||||||
resolveValueParameters(
|
resolveValueParameters(
|
||||||
constructorDescriptor,
|
constructorDescriptor,
|
||||||
semanticServices.createWritableScope(scope, classDescriptor),
|
new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler(), null),
|
||||||
valueParameters));
|
valueParameters));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +496,7 @@ public class ClassDescriptorResolver {
|
|||||||
if (modifierList != null) {
|
if (modifierList != null) {
|
||||||
ASTNode abstractNode = modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD);
|
ASTNode abstractNode = modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD);
|
||||||
if (abstractNode != null) {
|
if (abstractNode != null) {
|
||||||
semanticServices.getErrorHandler().genericError(abstractNode, "This property cannot be declared abstract");
|
trace.getErrorHandler().genericError(abstractNode, "This property cannot be declared abstract");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package org.jetbrains.jet.lang.resolve;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.types.*;
|
import org.jetbrains.jet.lang.types.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -26,10 +25,10 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
|
|||||||
private final WritableScope writableMemberScope;
|
private final WritableScope writableMemberScope;
|
||||||
private JetScope unsubstitutedMemberScope;
|
private JetScope unsubstitutedMemberScope;
|
||||||
|
|
||||||
public MutableClassDescriptor(@NotNull JetSemanticServices semanticServices, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
|
||||||
super(containingDeclaration);
|
super(containingDeclaration);
|
||||||
this.classHeaderScope = semanticServices.createWritableScope(outerScope, this);
|
this.classHeaderScope = new WritableScopeImpl(outerScope, this, trace.getErrorHandler(), null);
|
||||||
this.writableMemberScope = semanticServices.createWritableScope(classHeaderScope, this, new DeclarationDescriptorVisitor<Void, WritableScope>() {
|
this.writableMemberScope = new WritableScopeImpl(classHeaderScope, this, trace.getErrorHandler(), new DeclarationDescriptorVisitor<Void, WritableScope>() {
|
||||||
@Override
|
@Override
|
||||||
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, WritableScope data) {
|
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, WritableScope data) {
|
||||||
properties.add(descriptor);
|
properties.add(descriptor);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class TopDownAnalyzer {
|
|||||||
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
|
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
|
||||||
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||||
if (!trace.hasBackingField((PropertyDescriptor) descriptor)) {
|
if (!trace.hasBackingField((PropertyDescriptor) descriptor)) {
|
||||||
TopDownAnalyzer.this.semanticServices.getErrorHandler().genericError(expression.getNode(), "This property does not have a backing field");
|
TopDownAnalyzer.this.trace.getErrorHandler().genericError(expression.getNode(), "This property does not have a backing field");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,7 +86,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) {
|
public void process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) {
|
||||||
final WritableScope toplevelScope = semanticServices.createWritableScope(outerScope, outerScope.getContainingDeclaration()); // TODO ?!
|
final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?!
|
||||||
trace.setToplevelScope(toplevelScope); // TODO : this is a hack
|
trace.setToplevelScope(toplevelScope); // TODO : this is a hack
|
||||||
collectTypeDeclarators(toplevelScope, declarations);
|
collectTypeDeclarators(toplevelScope, declarations);
|
||||||
resolveTypeDeclarations();
|
resolveTypeDeclarations();
|
||||||
@@ -123,7 +123,7 @@ public class TopDownAnalyzer {
|
|||||||
Collections.<Annotation>emptyList(), // TODO
|
Collections.<Annotation>emptyList(), // TODO
|
||||||
name
|
name
|
||||||
);
|
);
|
||||||
namespaceDescriptor.initialize(semanticServices.createWritableScope(JetScope.EMPTY, namespaceDescriptor));
|
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler(), null));
|
||||||
declaringScope.addNamespace(namespaceDescriptor);
|
declaringScope.addNamespace(namespaceDescriptor);
|
||||||
trace.recordDeclarationResolution(namespace, namespaceDescriptor);
|
trace.recordDeclarationResolution(namespace, namespaceDescriptor);
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private WritableScope processClass(@NotNull WritableScope declaringScope, JetClass klass) {
|
private WritableScope processClass(@NotNull WritableScope declaringScope, JetClass klass) {
|
||||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(semanticServices, declaringScope.getContainingDeclaration(), declaringScope);
|
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope);
|
||||||
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
|
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
|
||||||
|
|
||||||
declaringScope.addClassifierDescriptor(mutableClassDescriptor);
|
declaringScope.addClassifierDescriptor(mutableClassDescriptor);
|
||||||
@@ -235,7 +235,7 @@ public class TopDownAnalyzer {
|
|||||||
processSecondaryConstructor((MutableClassDescriptor) containingDeclaration, constructor);
|
processSecondaryConstructor((MutableClassDescriptor) containingDeclaration, constructor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes");
|
trace.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDeclaration(JetDeclaration dcl) {
|
public void visitDeclaration(JetDeclaration dcl) {
|
||||||
semanticServices.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO
|
trace.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -301,7 +301,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void processClassObject(JetClassObject classObject) {
|
private void processClassObject(JetClassObject classObject) {
|
||||||
semanticServices.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO
|
trace.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -357,7 +357,7 @@ public class TopDownAnalyzer {
|
|||||||
if (trace.hasBackingField(propertyDescriptor)) {
|
if (trace.hasBackingField(propertyDescriptor)) {
|
||||||
PsiElement nameIdentifier = jetClass.getNameIdentifier();
|
PsiElement nameIdentifier = jetClass.getNameIdentifier();
|
||||||
if (nameIdentifier != null) {
|
if (nameIdentifier != null) {
|
||||||
semanticServices.getErrorHandler().genericError(nameIdentifier.getNode(),
|
trace.getErrorHandler().genericError(nameIdentifier.getNode(),
|
||||||
"This class must have a primary constructor, because property " + propertyDescriptor.getName() + " has a backing field");
|
"This class must have a primary constructor, because property " + propertyDescriptor.getName() + " has a backing field");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -386,7 +386,7 @@ public class TopDownAnalyzer {
|
|||||||
JetType type = typeInferrer.getType(scope, delegateExpression, false);
|
JetType type = typeInferrer.getType(scope, delegateExpression, false);
|
||||||
JetType supertype = trace.resolveTypeReference(specifier.getTypeReference());
|
JetType supertype = trace.resolveTypeReference(specifier.getTypeReference());
|
||||||
if (type != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { // TODO : Convertible?
|
if (type != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { // TODO : Convertible?
|
||||||
semanticServices.getErrorHandler().typeMismatch(delegateExpression, supertype, type);
|
trace.getErrorHandler().typeMismatch(delegateExpression, supertype, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,7 +398,7 @@ public class TopDownAnalyzer {
|
|||||||
if (!jetClass.hasPrimaryConstructor()) {
|
if (!jetClass.hasPrimaryConstructor()) {
|
||||||
JetArgumentList valueArgumentList = call.getValueArgumentList();
|
JetArgumentList valueArgumentList = call.getValueArgumentList();
|
||||||
assert valueArgumentList != null;
|
assert valueArgumentList != null;
|
||||||
semanticServices.getErrorHandler().genericError(valueArgumentList.getNode(),
|
trace.getErrorHandler().genericError(valueArgumentList.getNode(),
|
||||||
"Class " + JetPsiUtil.safeName(jetClass.getName()) + " must have a constructor in order to be able to initialize supertypes");
|
"Class " + JetPsiUtil.safeName(jetClass.getName()) + " must have a constructor in order to be able to initialize supertypes");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -415,11 +415,11 @@ public class TopDownAnalyzer {
|
|||||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||||
if (classDescriptor.hasConstructors()) {
|
if (classDescriptor.hasConstructors()) {
|
||||||
semanticServices.getErrorHandler().genericError(specifier.getNode(), "This type has a constructor, and thus must be initialized here");
|
trace.getErrorHandler().genericError(specifier.getNode(), "This type has a constructor, and thus must be initialized here");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(specifier.getNode(), "Only classes may serve as supertypes");
|
trace.getErrorHandler().genericError(specifier.getNode(), "Only classes may serve as supertypes");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -456,7 +456,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
|
||||||
semanticServices.getErrorHandler().genericError(anonymousInitializer.getNode(), "Anonymous initializers are only allowed in the presence of a primary constructor");
|
trace.getErrorHandler().genericError(anonymousInitializer.getNode(), "Anonymous initializers are only allowed in the presence of a primary constructor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -484,12 +484,12 @@ public class TopDownAnalyzer {
|
|||||||
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
|
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
|
||||||
assert containingClass != null : "This must be guaranteed by the parser";
|
assert containingClass != null : "This must be guaranteed by the parser";
|
||||||
if (!containingClass.hasPrimaryConstructor()) {
|
if (!containingClass.hasPrimaryConstructor()) {
|
||||||
semanticServices.getErrorHandler().genericError(declaration.getNameNode(), "A secondary constructor may appear only in a class that has a primary constructor");
|
trace.getErrorHandler().genericError(declaration.getNameNode(), "A secondary constructor may appear only in a class that has a primary constructor");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<JetDelegationSpecifier> initializers = declaration.getInitializers();
|
List<JetDelegationSpecifier> initializers = declaration.getInitializers();
|
||||||
if (initializers.isEmpty()) {
|
if (initializers.isEmpty()) {
|
||||||
semanticServices.getErrorHandler().genericError(declaration.getNameNode(), "Secondary constructors must have an initializer list");
|
trace.getErrorHandler().genericError(declaration.getNameNode(), "Secondary constructors must have an initializer list");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
initializers.get(0).accept(new JetVisitor() {
|
initializers.get(0).accept(new JetVisitor() {
|
||||||
@@ -516,12 +516,12 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) {
|
public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) {
|
||||||
semanticServices.getErrorHandler().genericError(specifier.getNode(), "'by'-clause is only supported for primary constructors");
|
trace.getErrorHandler().genericError(specifier.getNode(), "'by'-clause is only supported for primary constructors");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDelegationToSuperClassSpecifier(JetDelegatorToSuperClass specifier) {
|
public void visitDelegationToSuperClassSpecifier(JetDelegatorToSuperClass specifier) {
|
||||||
semanticServices.getErrorHandler().genericError(specifier.getNode(), "Constructor parameters required");
|
trace.getErrorHandler().genericError(specifier.getNode(), "Constructor parameters required");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -531,7 +531,7 @@ public class TopDownAnalyzer {
|
|||||||
});
|
});
|
||||||
for (int i = 1, initializersSize = initializers.size(); i < initializersSize; i++) {
|
for (int i = 1, initializersSize = initializers.size(); i < initializersSize; i++) {
|
||||||
JetDelegationSpecifier initializer = initializers.get(i);
|
JetDelegationSpecifier initializer = initializers.get(i);
|
||||||
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Only one call to 'this(...)' is allowed");
|
trace.getErrorHandler().genericError(initializer.getNode(), "Only one call to 'this(...)' is allowed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -547,11 +547,11 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope) {
|
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope) {
|
||||||
WritableScope constructorScope = semanticServices.createWritableScope(declaringScope, declaringScope.getContainingDeclaration());
|
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
for (PropertyDescriptor propertyDescriptor : declaringScopesToProperties.get(descriptor.getContainingDeclaration())) {
|
for (PropertyDescriptor propertyDescriptor : declaringScopesToProperties.get(descriptor.getContainingDeclaration())) {
|
||||||
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||||
}
|
}
|
||||||
return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, semanticServices);
|
return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, trace);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resolvePropertyDeclarationBodies() {
|
private void resolvePropertyDeclarationBodies() {
|
||||||
@@ -572,7 +572,7 @@ public class TopDownAnalyzer {
|
|||||||
if (initializer != null) {
|
if (initializer != null) {
|
||||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||||
if (primaryConstructor == null) {
|
if (primaryConstructor == null) {
|
||||||
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
|
trace.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getWritableUnsubstitutedMemberScope());
|
JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getWritableUnsubstitutedMemberScope());
|
||||||
@@ -605,7 +605,7 @@ public class TopDownAnalyzer {
|
|||||||
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, WritableScope declaringScope) {
|
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, WritableScope declaringScope) {
|
||||||
BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
|
BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
|
||||||
|
|
||||||
WritableScope accessorScope = semanticServices.createWritableScope(declaringScope, declaringScope.getContainingDeclaration());
|
WritableScope accessorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
|
||||||
|
|
||||||
JetPropertyAccessor getter = property.getGetter();
|
JetPropertyAccessor getter = property.getGetter();
|
||||||
@@ -622,7 +622,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
JetExpression initializer = property.getInitializer();
|
JetExpression initializer = property.getInitializer();
|
||||||
if (!property.isVar() && initializer != null && !trace.hasBackingField(propertyDescriptor)) {
|
if (!property.isVar() && initializer != null && !trace.hasBackingField(propertyDescriptor)) {
|
||||||
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no setter and no backing field either");
|
trace.getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no setter and no backing field either");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,7 +662,7 @@ public class TopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
if (type != null && expectedType != null
|
if (type != null && expectedType != null
|
||||||
&& !semanticServices.getTypeChecker().isConvertibleTo(type, expectedType)) {
|
&& !semanticServices.getTypeChecker().isConvertibleTo(type, expectedType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(initializer, expectedType, type);
|
trace.getErrorHandler().typeMismatch(initializer, expectedType, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -714,12 +714,12 @@ public class TopDownAnalyzer {
|
|||||||
// though it'd better be reported more specifically
|
// though it'd better be reported more specifically
|
||||||
|
|
||||||
for (JetElement element : rootElements) {
|
for (JetElement element : rootElements) {
|
||||||
semanticServices.getErrorHandler().genericError(element.getNode(), "Unreachable code");
|
trace.getErrorHandler().genericError(element.getNode(), "Unreachable code");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!functionDescriptor.isReturnTypeSet()) {
|
if (!functionDescriptor.isReturnTypeSet()) {
|
||||||
semanticServices.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
|
trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
|
||||||
functionDescriptor.setUnsubstitutedReturnType(ErrorUtils.createErrorType("No type, no body"));
|
functionDescriptor.setUnsubstitutedReturnType(ErrorUtils.createErrorType("No type, no body"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -844,7 +844,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) {
|
public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) {
|
||||||
semanticServices.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder " + instruction.getElement());
|
trace.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder " + instruction.getElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -866,7 +866,7 @@ public class TopDownAnalyzer {
|
|||||||
public void visitInstruction(Instruction instruction) {
|
public void visitInstruction(Instruction instruction) {
|
||||||
if (instruction instanceof JetElementInstructionImpl) {
|
if (instruction instanceof JetElementInstructionImpl) {
|
||||||
JetElementInstructionImpl elementInstruction = (JetElementInstructionImpl) instruction;
|
JetElementInstructionImpl elementInstruction = (JetElementInstructionImpl) instruction;
|
||||||
semanticServices.getErrorHandler().genericError(elementInstruction.getElement().getNode(), "Unsupported by control-flow builder " + elementInstruction.getElement());
|
trace.getErrorHandler().genericError(elementInstruction.getElement().getNode(), "Unsupported by control-flow builder " + elementInstruction.getElement());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException(instruction.toString());
|
throw new UnsupportedOperationException(instruction.toString());
|
||||||
|
|||||||
@@ -83,9 +83,9 @@ public class TypeResolver {
|
|||||||
if (actualArgumentCount != expectedArgumentCount) {
|
if (actualArgumentCount != expectedArgumentCount) {
|
||||||
String errorMessage = (expectedArgumentCount == 0 ? "No" : expectedArgumentCount) + " type arguments expected";
|
String errorMessage = (expectedArgumentCount == 0 ? "No" : expectedArgumentCount) + " type arguments expected";
|
||||||
if (actualArgumentCount == 0) {
|
if (actualArgumentCount == 0) {
|
||||||
semanticServices.getErrorHandler().genericError(type.getNode(), errorMessage);
|
trace.getErrorHandler().genericError(type.getNode(), errorMessage);
|
||||||
} else if (expectedArgumentCount == 0) {
|
} else if (expectedArgumentCount == 0) {
|
||||||
semanticServices.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage);
|
trace.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result[0] = new JetTypeImpl(
|
result[0] = new JetTypeImpl(
|
||||||
@@ -188,7 +188,7 @@ public class TypeResolver {
|
|||||||
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
|
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
|
||||||
|
|
||||||
if (classifierDescriptor == null) {
|
if (classifierDescriptor == null) {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
|
trace.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
return classifierDescriptor;
|
return classifierDescriptor;
|
||||||
@@ -231,7 +231,7 @@ public class TypeResolver {
|
|||||||
|
|
||||||
NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType);
|
NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType);
|
||||||
if (namespaceDescriptor == null) {
|
if (namespaceDescriptor == null) {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
|
trace.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return namespaceDescriptor.getMemberScope();
|
return namespaceDescriptor.getMemberScope();
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.ErrorHandler;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||||
|
|
||||||
@@ -59,6 +60,12 @@ public interface BindingTrace {
|
|||||||
@Override
|
@Override
|
||||||
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
|
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ErrorHandler getErrorHandler() {
|
||||||
|
return ErrorHandler.DO_NOTHING;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type);
|
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type);
|
||||||
@@ -84,4 +91,7 @@ public interface BindingTrace {
|
|||||||
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression);
|
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression);
|
||||||
|
|
||||||
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor);
|
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ErrorHandler getErrorHandler();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types;
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.ErrorHandler;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||||
|
|
||||||
@@ -62,6 +63,12 @@ public class BindingTraceAdapter implements BindingTrace {
|
|||||||
originalTrace.requireBackingField(propertyDescriptor);
|
originalTrace.requireBackingField(propertyDescriptor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ErrorHandler getErrorHandler() {
|
||||||
|
return originalTrace.getErrorHandler();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeStatementRecord(@NotNull JetElement statement) {
|
public void removeStatementRecord(@NotNull JetElement statement) {
|
||||||
originalTrace.removeStatementRecord(statement);
|
originalTrace.removeStatementRecord(statement);
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import com.google.common.collect.HashBiMap;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
|
||||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||||
import org.jetbrains.jet.lang.resolve.WritableScope;
|
import org.jetbrains.jet.lang.resolve.WritableScope;
|
||||||
|
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -95,8 +95,8 @@ public class FunctionDescriptorUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull JetSemanticServices semanticServices) {
|
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
|
||||||
WritableScope parameterScope = semanticServices.createWritableScope(outerScope, descriptor);
|
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace.getErrorHandler(), null);
|
||||||
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
|
||||||
parameterScope.addTypeParameterDescriptor(typeParameter);
|
parameterScope.addTypeParameterDescriptor(typeParameter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.intellij.openapi.project.Project;
|
|||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.psi.PsiFileFactory;
|
import com.intellij.psi.PsiFileFactory;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.ErrorHandler;
|
|
||||||
import org.jetbrains.jet.lang.JetFileType;
|
import org.jetbrains.jet.lang.JetFileType;
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
@@ -69,7 +68,7 @@ public class JetStandardLibrary {
|
|||||||
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
|
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
|
||||||
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
|
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
|
||||||
|
|
||||||
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this, ErrorHandler.DO_NOTHING);
|
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
|
||||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||||
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext);
|
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext);
|
||||||
bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
|
||||||
|
|||||||
@@ -184,7 +184,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitJetElement(JetElement elem) {
|
public void visitJetElement(JetElement elem) {
|
||||||
semanticServices.getErrorHandler().genericError(elem.getNode(), "Unsupported in call element"); // TODO : Message
|
trace.getErrorHandler().genericError(elem.getNode(), "Unsupported in call element"); // TODO : Message
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return wrapForTracing(result[0], reference[0], argumentList, true);
|
return wrapForTracing(result[0], reference[0], argumentList, true);
|
||||||
@@ -195,14 +195,14 @@ public class JetTypeInferrer {
|
|||||||
boolean namespaceType = receiverType instanceof NamespaceType;
|
boolean namespaceType = receiverType instanceof NamespaceType;
|
||||||
boolean nullable = !namespaceType && receiverType.isNullable();
|
boolean nullable = !namespaceType && receiverType.isNullable();
|
||||||
if (nullable && expression.getOperationSign() == JetTokens.DOT) {
|
if (nullable && expression.getOperationSign() == JetTokens.DOT) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Only safe calls (?.) are allowed on a nullable receiver of type " + receiverType);
|
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Only safe calls (?.) are allowed on a nullable receiver of type " + receiverType);
|
||||||
}
|
}
|
||||||
else if (!nullable && expression.getOperationSign() == JetTokens.SAFE_ACCESS) {
|
else if (!nullable && expression.getOperationSign() == JetTokens.SAFE_ACCESS) {
|
||||||
if (namespaceType) {
|
if (namespaceType) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Safe calls are not allowed on namespaces");
|
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Safe calls are not allowed on namespaces");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericWarning(expression.getOperationTokenNode(), "Unnecessary safe call on a non-null receiver of type " + receiverType);
|
trace.getErrorHandler().genericWarning(expression.getOperationTokenNode(), "Unnecessary safe call on a non-null receiver of type " + receiverType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,24 +239,24 @@ public class JetTypeInferrer {
|
|||||||
if (reportErrors) {
|
if (reportErrors) {
|
||||||
switch (resolutionResult.getResultCode()) {
|
switch (resolutionResult.getResultCode()) {
|
||||||
case NAME_NOT_FOUND:
|
case NAME_NOT_FOUND:
|
||||||
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
|
trace.getErrorHandler().unresolvedReference(referenceExpression);
|
||||||
break;
|
break;
|
||||||
case SINGLE_FUNCTION_ARGUMENT_MISMATCH:
|
case SINGLE_FUNCTION_ARGUMENT_MISMATCH:
|
||||||
if (argumentList != null) {
|
if (argumentList != null) {
|
||||||
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
|
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
|
||||||
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Arguments do not match " + DescriptorUtil.renderPresentableText(resolutionResult.getFunctionDescriptor()));
|
trace.getErrorHandler().genericError(argumentList.getNode(), "Arguments do not match " + DescriptorUtil.renderPresentableText(resolutionResult.getFunctionDescriptor()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
|
trace.getErrorHandler().unresolvedReference(referenceExpression);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AMBIGUITY:
|
case AMBIGUITY:
|
||||||
if (argumentList != null) {
|
if (argumentList != null) {
|
||||||
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
|
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
|
||||||
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Overload ambiguity [TODO : more helpful message]");
|
trace.getErrorHandler().genericError(argumentList.getNode(), "Overload ambiguity [TODO : more helpful message]");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
|
trace.getErrorHandler().unresolvedReference(referenceExpression);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -298,21 +298,21 @@ public class JetTypeInferrer {
|
|||||||
if (typeChecker.isConvertibleBySpecialConversion(actualType, expectedReturnType)) {
|
if (typeChecker.isConvertibleBySpecialConversion(actualType, expectedReturnType)) {
|
||||||
if (expectedReturnType.getConstructor().equals(JetStandardClasses.getUnitType().getConstructor())
|
if (expectedReturnType.getConstructor().equals(JetStandardClasses.getUnitType().getConstructor())
|
||||||
&& element.getParent() instanceof JetReturnExpression) {
|
&& element.getParent() instanceof JetReturnExpression) {
|
||||||
semanticServices.getErrorHandler().genericError(element.getNode(), "This function must return a value of type Unit");
|
trace.getErrorHandler().genericError(element.getNode(), "This function must return a value of type Unit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (element == function) {
|
if (element == function) {
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
assert bodyExpression != null;
|
assert bodyExpression != null;
|
||||||
semanticServices.getErrorHandler().genericError(bodyExpression.getNode(), "This function must return a value of type " + expectedReturnType);
|
trace.getErrorHandler().genericError(bodyExpression.getNode(), "This function must return a value of type " + expectedReturnType);
|
||||||
}
|
}
|
||||||
else if (element instanceof JetExpression) {
|
else if (element instanceof JetExpression) {
|
||||||
JetExpression expression = (JetExpression) element;
|
JetExpression expression = (JetExpression) element;
|
||||||
semanticServices.getErrorHandler().typeMismatch(expression, expectedReturnType, actualType);
|
trace.getErrorHandler().typeMismatch(expression, expectedReturnType, actualType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(element.getNode(), "This function must return a value of type " + expectedReturnType);
|
trace.getErrorHandler().genericError(element.getNode(), "This function must return a value of type " + expectedReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,7 +322,7 @@ public class JetTypeInferrer {
|
|||||||
private Map<JetElement, JetType> collectReturnedExpressions(JetScope outerScope, JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) {
|
private Map<JetElement, JetType> collectReturnedExpressions(JetScope outerScope, JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) {
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
assert bodyExpression != null;
|
assert bodyExpression != null;
|
||||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, semanticServices);
|
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
|
||||||
getType(functionInnerScope, bodyExpression, function.hasBlockBody());
|
getType(functionInnerScope, bodyExpression, function.hasBlockBody());
|
||||||
Collection<JetExpression> returnedExpressions = new ArrayList<JetExpression>();
|
Collection<JetExpression> returnedExpressions = new ArrayList<JetExpression>();
|
||||||
Collection<JetElement> elementsReturningUnit = new ArrayList<JetElement>();
|
Collection<JetElement> elementsReturningUnit = new ArrayList<JetElement>();
|
||||||
@@ -348,7 +348,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
|
||||||
WritableScope scope = semanticServices.createWritableScope(outerScope, containingDescriptor);
|
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, trace.getErrorHandler(), null);
|
||||||
return getBlockReturnedTypeWithWritableScope(scope, block);
|
return getBlockReturnedTypeWithWritableScope(scope, block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -403,7 +403,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
for (JetTypeProjection typeArgument : typeArguments) {
|
for (JetTypeProjection typeArgument : typeArguments) {
|
||||||
if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) {
|
if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) {
|
||||||
semanticServices.getErrorHandler().genericError(typeArgument.getNode(), "Projections are not allowed on type parameters for methods"); // TODO : better positioning
|
trace.getErrorHandler().genericError(typeArgument.getNode(), "Projections are not allowed on type parameters for methods"); // TODO : better positioning
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -478,7 +478,7 @@ public class JetTypeInferrer {
|
|||||||
case OUT:
|
case OUT:
|
||||||
case STAR:
|
case STAR:
|
||||||
// TODO : Bug in the editor
|
// TODO : Bug in the editor
|
||||||
semanticServices.getErrorHandler().genericError(typeProjection.getProjectionNode(), "Projections are not allowed in constructor type arguments");
|
trace.getErrorHandler().genericError(typeProjection.getProjectionNode(), "Projections are not allowed in constructor type arguments");
|
||||||
break;
|
break;
|
||||||
case NONE:
|
case NONE:
|
||||||
break;
|
break;
|
||||||
@@ -491,12 +491,12 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(((JetElement) call).getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : review the message
|
trace.getErrorHandler().genericError(((JetElement) call).getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : review the message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (typeElement != null) {
|
if (typeElement != null) {
|
||||||
semanticServices.getErrorHandler().genericError(typeElement.getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : Better message
|
trace.getErrorHandler().genericError(typeElement.getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : Better message
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -546,7 +546,7 @@ public class JetTypeInferrer {
|
|||||||
// TODO : more helpful message
|
// TODO : more helpful message
|
||||||
JetArgumentList argumentList = call.getValueArgumentList();
|
JetArgumentList argumentList = call.getValueArgumentList();
|
||||||
if (argumentList != null) {
|
if (argumentList != null) {
|
||||||
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Cannot find an overload for these arguments");
|
trace.getErrorHandler().genericError(argumentList.getNode(), "Cannot find an overload for these arguments");
|
||||||
}
|
}
|
||||||
constructorReturnedType = receiverType;
|
constructorReturnedType = receiverType;
|
||||||
}
|
}
|
||||||
@@ -615,7 +615,7 @@ public class JetTypeInferrer {
|
|||||||
flowInformationProvider.collectDominatedExpressions(expression, dominated);
|
flowInformationProvider.collectDominatedExpressions(expression, dominated);
|
||||||
Set<JetElement> rootExpressions = JetPsiUtil.findRootExpressions(dominated);
|
Set<JetElement> rootExpressions = JetPsiUtil.findRootExpressions(dominated);
|
||||||
for (JetElement rootExpression : rootExpressions) {
|
for (JetElement rootExpression : rootExpressions) {
|
||||||
semanticServices.getErrorHandler().genericError(rootExpression.getNode(),
|
trace.getErrorHandler().genericError(rootExpression.getNode(),
|
||||||
"This code is unreachable, because '" + expression.getText() + "' never terminates normally");
|
"This code is unreachable, because '" + expression.getText() + "' never terminates normally");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -631,7 +631,7 @@ public class JetTypeInferrer {
|
|||||||
&& referencedName != null) {
|
&& referencedName != null) {
|
||||||
PropertyDescriptor property = scope.getPropertyByFieldReference(referencedName);
|
PropertyDescriptor property = scope.getPropertyByFieldReference(referencedName);
|
||||||
if (property == null) {
|
if (property == null) {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(expression);
|
trace.getErrorHandler().unresolvedReference(expression);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
trace.recordReferenceResolution(expression, property);
|
trace.recordReferenceResolution(expression, property);
|
||||||
@@ -646,13 +646,13 @@ public class JetTypeInferrer {
|
|||||||
trace.recordReferenceResolution(expression, variable);
|
trace.recordReferenceResolution(expression, variable);
|
||||||
result = variable.getOutType();
|
result = variable.getOutType();
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
|
trace.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (furtherNameLookup(expression, referencedName)) {
|
} else if (furtherNameLookup(expression, referencedName)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
semanticServices.getErrorHandler().unresolvedReference(expression);
|
trace.getErrorHandler().unresolvedReference(expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,7 +660,7 @@ public class JetTypeInferrer {
|
|||||||
protected boolean furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName) {
|
protected boolean furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName) {
|
||||||
NamespaceType namespaceType = lookupNamespaceType(expression, referencedName);
|
NamespaceType namespaceType = lookupNamespaceType(expression, referencedName);
|
||||||
if (namespaceType != null) {
|
if (namespaceType != null) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found");
|
trace.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -712,7 +712,7 @@ public class JetTypeInferrer {
|
|||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = typeResolver.resolveType(scope, returnTypeRef);
|
returnType = typeResolver.resolveType(scope, returnTypeRef);
|
||||||
} else {
|
} else {
|
||||||
WritableScope writableScope = semanticServices.createWritableScope(scope, functionDescriptor);
|
WritableScope writableScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler(), null);
|
||||||
for (VariableDescriptor variableDescriptor : parameterDescriptors.values()) {
|
for (VariableDescriptor variableDescriptor : parameterDescriptors.values()) {
|
||||||
writableScope.addVariableDescriptor(variableDescriptor);
|
writableScope.addVariableDescriptor(variableDescriptor);
|
||||||
}
|
}
|
||||||
@@ -739,7 +739,7 @@ public class JetTypeInferrer {
|
|||||||
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
|
||||||
Object value = expression.getValue();
|
Object value = expression.getValue();
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Number is of range for Long");
|
trace.getErrorHandler().genericError(expression.getNode(), "Number is of range for Long");
|
||||||
}
|
}
|
||||||
else if (value instanceof Long) {
|
else if (value instanceof Long) {
|
||||||
result = standardLibrary.getLongType();
|
result = standardLibrary.getLongType();
|
||||||
@@ -813,7 +813,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTypeofExpression(JetTypeofExpression expression) {
|
public void visitTypeofExpression(JetTypeofExpression expression) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO
|
trace.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -825,7 +825,7 @@ public class JetTypeInferrer {
|
|||||||
JetType targetType = typeResolver.resolveType(scope, right);
|
JetType targetType = typeResolver.resolveType(scope, right);
|
||||||
if (operationType == JetTokens.COLON) {
|
if (operationType == JetTokens.COLON) {
|
||||||
if (actualType != null && !semanticServices.getTypeChecker().isSubtypeOf(actualType, targetType)) {
|
if (actualType != null && !semanticServices.getTypeChecker().isSubtypeOf(actualType, targetType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(expression.getLeft(), targetType, actualType);
|
trace.getErrorHandler().typeMismatch(expression.getLeft(), targetType, actualType);
|
||||||
}
|
}
|
||||||
result = targetType;
|
result = targetType;
|
||||||
}
|
}
|
||||||
@@ -838,7 +838,7 @@ public class JetTypeInferrer {
|
|||||||
result = TypeUtils.makeNullable(targetType);
|
result = TypeUtils.makeNullable(targetType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation");
|
trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -849,15 +849,15 @@ public class JetTypeInferrer {
|
|||||||
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
|
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
|
||||||
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
|
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
|
||||||
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
||||||
semanticServices.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed, use ':' instead");
|
trace.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed, use ':' instead");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getOperationSign().getNode(), "This cast can never succeed");
|
trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "This cast can never succeed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
if (typeChecker.isSubtypeOf(actualType, targetType)) {
|
||||||
semanticServices.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed");
|
trace.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -892,12 +892,12 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (size == 0) {
|
else if (size == 0) {
|
||||||
semanticServices.getErrorHandler().unresolvedReference(expression.getTargetLabel());
|
trace.getErrorHandler().unresolvedReference(expression.getTargetLabel());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetSimpleNameExpression labelElement = expression.getTargetLabel();
|
JetSimpleNameExpression labelElement = expression.getTargetLabel();
|
||||||
assert labelElement != null;
|
assert labelElement != null;
|
||||||
semanticServices.getErrorHandler().genericError(labelElement.getNode(), "Ambiguous label");
|
trace.getErrorHandler().genericError(labelElement.getNode(), "Ambiguous label");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -906,7 +906,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
if (thisType != null) {
|
if (thisType != null) {
|
||||||
if (JetStandardClasses.isNothing(thisType)) {
|
if (JetStandardClasses.isNothing(thisType)) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "'this' is not defined in this context");
|
trace.getErrorHandler().genericError(expression.getNode(), "'this' is not defined in this context");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
|
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
|
||||||
@@ -929,7 +929,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
semanticServices.getErrorHandler().genericError(superTypeElement.getNode(), "Not a superclass");
|
trace.getErrorHandler().genericError(superTypeElement.getNode(), "Not a superclass");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -965,7 +965,7 @@ public class JetTypeInferrer {
|
|||||||
if (catchParameter != null) {
|
if (catchParameter != null) {
|
||||||
VariableDescriptor variableDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, catchParameter);
|
VariableDescriptor variableDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, catchParameter);
|
||||||
if (catchBody != null) {
|
if (catchBody != null) {
|
||||||
WritableScope catchScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
|
WritableScope catchScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
catchScope.addVariableDescriptor(variableDescriptor);
|
catchScope.addVariableDescriptor(variableDescriptor);
|
||||||
JetType type = getType(catchScope, catchBody, true);
|
JetType type = getType(catchScope, catchBody, true);
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
@@ -1031,7 +1031,7 @@ public class JetTypeInferrer {
|
|||||||
JetType conditionType = getType(scope, condition, false);
|
JetType conditionType = getType(scope, condition, false);
|
||||||
|
|
||||||
if (conditionType != null && !isBoolean(conditionType)) {
|
if (conditionType != null && !isBoolean(conditionType)) {
|
||||||
semanticServices.getErrorHandler().genericError(condition.getNode(), "Condition must be of type Boolean, but was of type " + conditionType);
|
trace.getErrorHandler().genericError(condition.getNode(), "Condition must be of type Boolean, but was of type " + conditionType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1053,7 +1053,7 @@ public class JetTypeInferrer {
|
|||||||
if (body instanceof JetFunctionLiteralExpression) {
|
if (body instanceof JetFunctionLiteralExpression) {
|
||||||
JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body;
|
JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body;
|
||||||
if (!function.hasParameterSpecification()) {
|
if (!function.hasParameterSpecification()) {
|
||||||
WritableScope writableScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
|
WritableScope writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
conditionScope = writableScope;
|
conditionScope = writableScope;
|
||||||
getBlockReturnedTypeWithWritableScope(writableScope, function.getBody());
|
getBlockReturnedTypeWithWritableScope(writableScope, function.getBody());
|
||||||
trace.recordBlock(function);
|
trace.recordBlock(function);
|
||||||
@@ -1062,7 +1062,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (body != null) {
|
else if (body != null) {
|
||||||
WritableScope writableScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
|
WritableScope writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
conditionScope = writableScope;
|
conditionScope = writableScope;
|
||||||
getBlockReturnedTypeWithWritableScope(writableScope, Collections.singletonList(body));
|
getBlockReturnedTypeWithWritableScope(writableScope, Collections.singletonList(body));
|
||||||
}
|
}
|
||||||
@@ -1083,7 +1083,7 @@ public class JetTypeInferrer {
|
|||||||
expectedParameterType = checkIterableConvention(loopRangeType, loopRange.getNode());
|
expectedParameterType = checkIterableConvention(loopRangeType, loopRange.getNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
WritableScope loopScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
|
WritableScope loopScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
|
||||||
|
|
||||||
if (loopParameter != null) {
|
if (loopParameter != null) {
|
||||||
JetTypeReference typeReference = loopParameter.getTypeReference();
|
JetTypeReference typeReference = loopParameter.getTypeReference();
|
||||||
@@ -1094,7 +1094,7 @@ public class JetTypeInferrer {
|
|||||||
if (expectedParameterType != null &&
|
if (expectedParameterType != null &&
|
||||||
actualParameterType != null &&
|
actualParameterType != null &&
|
||||||
!semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
|
!semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
|
||||||
semanticServices.getErrorHandler().genericError(typeReference.getNode(), "The loop iterates over values of type " + expectedParameterType + " but the parameter is declared to be " + actualParameterType);
|
trace.getErrorHandler().genericError(typeReference.getNode(), "The loop iterates over values of type " + expectedParameterType + " but the parameter is declared to be " + actualParameterType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -1123,17 +1123,17 @@ public class JetTypeInferrer {
|
|||||||
boolean hasNextPropertySupported = checkHasNextPropertySupport(reportErrorsOn, iteratorType);
|
boolean hasNextPropertySupported = checkHasNextPropertySupport(reportErrorsOn, iteratorType);
|
||||||
if (hasNextFunctionSupported && hasNextPropertySupported && !ErrorUtils.isErrorType(iteratorType)) {
|
if (hasNextFunctionSupported && hasNextPropertySupported && !ErrorUtils.isErrorType(iteratorType)) {
|
||||||
// TODO : overload resolution rules impose priorities here???
|
// TODO : overload resolution rules impose priorities here???
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext()' property");
|
trace.getErrorHandler().genericError(reportErrorsOn, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext()' property");
|
||||||
}
|
}
|
||||||
else if (!hasNextFunctionSupported && !hasNextPropertySupported) {
|
else if (!hasNextFunctionSupported && !hasNextPropertySupported) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
|
trace.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
|
||||||
}
|
}
|
||||||
|
|
||||||
OverloadResolutionResult nextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "next");
|
OverloadResolutionResult nextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "next");
|
||||||
if (nextResolutionResult.isAmbiguity()) {
|
if (nextResolutionResult.isAmbiguity()) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().next()' is ambiguous for this expression");
|
trace.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().next()' is ambiguous for this expression");
|
||||||
} else if (nextResolutionResult.isNothing()) {
|
} else if (nextResolutionResult.isNothing()) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().next()' method");
|
trace.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().next()' method");
|
||||||
} else {
|
} else {
|
||||||
return nextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
|
return nextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
|
||||||
}
|
}
|
||||||
@@ -1143,7 +1143,7 @@ public class JetTypeInferrer {
|
|||||||
if (iteratorResolutionResult.isAmbiguity()) {
|
if (iteratorResolutionResult.isAmbiguity()) {
|
||||||
errorMessage = "Method 'iterator()' is ambiguous for this expression";
|
errorMessage = "Method 'iterator()' is ambiguous for this expression";
|
||||||
}
|
}
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, errorMessage);
|
trace.getErrorHandler().genericError(reportErrorsOn, errorMessage);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1151,13 +1151,13 @@ public class JetTypeInferrer {
|
|||||||
private boolean checkHasNextFunctionSupport(@NotNull ASTNode reportErrorsOn, @NotNull JetType iteratorType) {
|
private boolean checkHasNextFunctionSupport(@NotNull ASTNode reportErrorsOn, @NotNull JetType iteratorType) {
|
||||||
OverloadResolutionResult hasNextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "hasNext");
|
OverloadResolutionResult hasNextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "hasNext");
|
||||||
if (hasNextResolutionResult.isAmbiguity()) {
|
if (hasNextResolutionResult.isAmbiguity()) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().hasNext()' is ambiguous for this expression");
|
trace.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().hasNext()' is ambiguous for this expression");
|
||||||
} else if (hasNextResolutionResult.isNothing()) {
|
} else if (hasNextResolutionResult.isNothing()) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
JetType hasNextReturnType = hasNextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
|
JetType hasNextReturnType = hasNextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
|
||||||
if (!isBoolean(hasNextReturnType)) {
|
if (!isBoolean(hasNextReturnType)) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext()' method of the loop range must return Boolean, but returns " + hasNextReturnType);
|
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext()' method of the loop range must return Boolean, but returns " + hasNextReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1172,10 +1172,10 @@ public class JetTypeInferrer {
|
|||||||
JetType hasNextReturnType = hasNextProperty.getOutType();
|
JetType hasNextReturnType = hasNextProperty.getOutType();
|
||||||
if (hasNextReturnType == null) {
|
if (hasNextReturnType == null) {
|
||||||
// TODO : accessibility
|
// TODO : accessibility
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must be readable");
|
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must be readable");
|
||||||
}
|
}
|
||||||
else if (!isBoolean(hasNextReturnType)) {
|
else if (!isBoolean(hasNextReturnType)) {
|
||||||
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns " + hasNextReturnType);
|
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns " + hasNextReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -1198,7 +1198,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitHashQualifiedExpression(JetHashQualifiedExpression expression) {
|
public void visitHashQualifiedExpression(JetHashQualifiedExpression expression) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Unsupported");
|
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Unsupported");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1213,7 +1213,7 @@ public class JetTypeInferrer {
|
|||||||
if (expression.getOperationSign() == JetTokens.QUEST) {
|
if (expression.getOperationSign() == JetTokens.QUEST) {
|
||||||
if (selectorReturnType != null && !isBoolean(selectorReturnType)) {
|
if (selectorReturnType != null && !isBoolean(selectorReturnType)) {
|
||||||
// TODO : more comprehensible error message
|
// TODO : more comprehensible error message
|
||||||
semanticServices.getErrorHandler().typeMismatch(selectorExpression, semanticServices.getStandardLibrary().getBooleanType(), selectorReturnType);
|
trace.getErrorHandler().typeMismatch(selectorExpression, semanticServices.getStandardLibrary().getBooleanType(), selectorReturnType);
|
||||||
}
|
}
|
||||||
result = TypeUtils.makeNullable(receiverType);
|
result = TypeUtils.makeNullable(receiverType);
|
||||||
}
|
}
|
||||||
@@ -1238,7 +1238,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
else if (selectorExpression != null) {
|
else if (selectorExpression != null) {
|
||||||
// TODO : not a simple name -> resolve in scope, expect property type or a function type
|
// TODO : not a simple name -> resolve in scope, expect property type or a function type
|
||||||
semanticServices.getErrorHandler().genericError(selectorExpression.getNode(), "Unsupported selector element type: " + selectorExpression);
|
trace.getErrorHandler().genericError(selectorExpression.getNode(), "Unsupported selector element type: " + selectorExpression);
|
||||||
}
|
}
|
||||||
return receiverType;
|
return receiverType;
|
||||||
}
|
}
|
||||||
@@ -1267,7 +1267,7 @@ public class JetTypeInferrer {
|
|||||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||||
String name = unaryOperationNames.get(operationType);
|
String name = unaryOperationNames.get(operationType);
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
|
trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
JetType receiverType = getType(scope, expression.getBaseExpression(), false);
|
JetType receiverType = getType(scope, expression.getBaseExpression(), false);
|
||||||
@@ -1281,7 +1281,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
|
trace.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
|
||||||
}
|
}
|
||||||
// TODO : Maybe returnType?
|
// TODO : Maybe returnType?
|
||||||
result = receiverType;
|
result = receiverType;
|
||||||
@@ -1326,7 +1326,7 @@ public class JetTypeInferrer {
|
|||||||
if (constructor.equals(intTypeConstructor)) {
|
if (constructor.equals(intTypeConstructor)) {
|
||||||
result = standardLibrary.getBooleanType();
|
result = standardLibrary.getBooleanType();
|
||||||
} else {
|
} else {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "compareTo must return Int, but returns " + compareToReturnType);
|
trace.getErrorHandler().genericError(operationSign.getNode(), "compareTo must return Int, but returns " + compareToReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1346,7 +1346,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "No method 'equals(Any?) : Boolean' available");
|
trace.getErrorHandler().genericError(operationSign.getNode(), "No method 'equals(Any?) : Boolean' available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1373,10 +1373,10 @@ public class JetTypeInferrer {
|
|||||||
JetType leftType = getType(scope, left, false);
|
JetType leftType = getType(scope, left, false);
|
||||||
JetType rightType = right == null ? null : getType(scope, right, false);
|
JetType rightType = right == null ? null : getType(scope, right, false);
|
||||||
if (leftType != null && !isBoolean(leftType)) {
|
if (leftType != null && !isBoolean(leftType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(left, semanticServices.getStandardLibrary().getBooleanType(), leftType);
|
trace.getErrorHandler().typeMismatch(left, semanticServices.getStandardLibrary().getBooleanType(), leftType);
|
||||||
}
|
}
|
||||||
if (rightType != null && !isBoolean(rightType)) {
|
if (rightType != null && !isBoolean(rightType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(right, semanticServices.getStandardLibrary().getBooleanType(), rightType);
|
trace.getErrorHandler().typeMismatch(right, semanticServices.getStandardLibrary().getBooleanType(), rightType);
|
||||||
}
|
}
|
||||||
result = semanticServices.getStandardLibrary().getBooleanType();
|
result = semanticServices.getStandardLibrary().getBooleanType();
|
||||||
}
|
}
|
||||||
@@ -1385,7 +1385,7 @@ public class JetTypeInferrer {
|
|||||||
JetType rightType = right == null ? null : getType(scope, right, false);
|
JetType rightType = right == null ? null : getType(scope, right, false);
|
||||||
if (leftType != null) {
|
if (leftType != null) {
|
||||||
if (!leftType.isNullable()) {
|
if (!leftType.isNullable()) {
|
||||||
semanticServices.getErrorHandler().genericWarning(left.getNode(), "Elvis operator (?:) is always returns the left operand of non-nullable type " + leftType);
|
trace.getErrorHandler().genericWarning(left.getNode(), "Elvis operator (?:) is always returns the left operand of non-nullable type " + leftType);
|
||||||
}
|
}
|
||||||
if (rightType != null) {
|
if (rightType != null) {
|
||||||
result = TypeUtils.makeNullableAsSpecified(semanticServices.getTypeChecker().commonSupertype(leftType, rightType), rightType.isNullable());
|
result = TypeUtils.makeNullableAsSpecified(semanticServices.getTypeChecker().commonSupertype(leftType, rightType), rightType.isNullable());
|
||||||
@@ -1393,7 +1393,7 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "Unknown operation");
|
trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown operation");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1410,7 +1410,7 @@ public class JetTypeInferrer {
|
|||||||
if (rightType != null) {
|
if (rightType != null) {
|
||||||
JetType intersect = TypeUtils.intersect(semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
JetType intersect = TypeUtils.intersect(semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
|
||||||
if (intersect == null) {
|
if (intersect == null) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
|
trace.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1425,14 +1425,14 @@ public class JetTypeInferrer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void assignmentIsNotAnExpressionError(JetBinaryExpression expression) {
|
private void assignmentIsNotAnExpressionError(JetBinaryExpression expression) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "Assignments are not expressions, and only expressions are allowed in this context");
|
trace.getErrorHandler().genericError(expression.getNode(), "Assignments are not expressions, and only expressions are allowed in this context");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean ensureBooleanResult(JetSimpleNameExpression operationSign, String name, JetType resultType) {
|
private boolean ensureBooleanResult(JetSimpleNameExpression operationSign, String name, JetType resultType) {
|
||||||
if (resultType != null) {
|
if (resultType != null) {
|
||||||
// TODO : Relax?
|
// TODO : Relax?
|
||||||
if (!isBoolean(resultType)) {
|
if (!isBoolean(resultType)) {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "'" + name + "' must return Boolean but returns " + resultType);
|
trace.getErrorHandler().genericError(operationSign.getNode(), "'" + name + "' must return Boolean but returns " + resultType);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1491,7 +1491,7 @@ public class JetTypeInferrer {
|
|||||||
if (functionDescriptor != null) {
|
if (functionDescriptor != null) {
|
||||||
if (leftType.isNullable()) {
|
if (leftType.isNullable()) {
|
||||||
// TODO : better error message for '1 + nullableVar' case
|
// TODO : better error message for '1 + nullableVar' case
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(),
|
trace.getErrorHandler().genericError(operationSign.getNode(),
|
||||||
"Infix call corresponds to a dot-qualified call '" +
|
"Infix call corresponds to a dot-qualified call '" +
|
||||||
left.getText() + "." + name + "(" + right.getText() + ")'" +
|
left.getText() + "." + name + "(" + right.getText() + ")'" +
|
||||||
" which is not allowed on a nullable receiver '" + right.getText() + "'." +
|
" which is not allowed on a nullable receiver '" + right.getText() + "'." +
|
||||||
@@ -1505,18 +1505,18 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitDeclaration(JetDeclaration dcl) {
|
public void visitDeclaration(JetDeclaration dcl) {
|
||||||
semanticServices.getErrorHandler().genericError(dcl.getNode(), "Declarations are not allowed in this position");
|
trace.getErrorHandler().genericError(dcl.getNode(), "Declarations are not allowed in this position");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitRootNamespaceExpression(JetRootNamespaceExpression expression) {
|
public void visitRootNamespaceExpression(JetRootNamespaceExpression expression) {
|
||||||
semanticServices.getErrorHandler().genericError(expression.getNode(), "'namespace' is not an expression");
|
trace.getErrorHandler().genericError(expression.getNode(), "'namespace' is not an expression");
|
||||||
result = null;
|
result = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitJetElement(JetElement elem) {
|
public void visitJetElement(JetElement elem) {
|
||||||
semanticServices.getErrorHandler().genericError(elem.getNode(), "[JetTypeInferrer] Unsupported element: " + elem + " " + elem.getClass().getCanonicalName());
|
trace.getErrorHandler().genericError(elem.getNode(), "[JetTypeInferrer] Unsupported element: " + elem + " " + elem.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1557,12 +1557,12 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
JetPropertyAccessor getter = property.getGetter();
|
JetPropertyAccessor getter = property.getGetter();
|
||||||
if (getter != null) {
|
if (getter != null) {
|
||||||
semanticServices.getErrorHandler().genericError(getter.getNode(), "Local variables are not allowed to have getters");
|
trace.getErrorHandler().genericError(getter.getNode(), "Local variables are not allowed to have getters");
|
||||||
}
|
}
|
||||||
|
|
||||||
JetPropertyAccessor setter = property.getSetter();
|
JetPropertyAccessor setter = property.getSetter();
|
||||||
if (setter != null) {
|
if (setter != null) {
|
||||||
semanticServices.getErrorHandler().genericError(setter.getNode(), "Local variables are not allowed to have setters");
|
trace.getErrorHandler().genericError(setter.getNode(), "Local variables are not allowed to have setters");
|
||||||
}
|
}
|
||||||
|
|
||||||
VariableDescriptor propertyDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property);
|
VariableDescriptor propertyDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property);
|
||||||
@@ -1573,7 +1573,7 @@ public class JetTypeInferrer {
|
|||||||
if (outType != null &&
|
if (outType != null &&
|
||||||
initializerType != null &&
|
initializerType != null &&
|
||||||
!semanticServices.getTypeChecker().isConvertibleTo(initializerType, outType)) {
|
!semanticServices.getTypeChecker().isConvertibleTo(initializerType, outType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(initializer, outType, initializerType);
|
trace.getErrorHandler().typeMismatch(initializer, outType, initializerType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1634,7 +1634,7 @@ public class JetTypeInferrer {
|
|||||||
if (rightType != null &&
|
if (rightType != null &&
|
||||||
leftType != null &&
|
leftType != null &&
|
||||||
!semanticServices.getTypeChecker().isConvertibleTo(rightType, leftType)) {
|
!semanticServices.getTypeChecker().isConvertibleTo(rightType, leftType)) {
|
||||||
semanticServices.getErrorHandler().typeMismatch(right, leftType, rightType);
|
trace.getErrorHandler().typeMismatch(right, leftType, rightType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1661,7 +1661,7 @@ public class JetTypeInferrer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitJetElement(JetElement elem) {
|
public void visitJetElement(JetElement elem) {
|
||||||
semanticServices.getErrorHandler().genericError(elem.getNode(), "Unsupported element in a block: " + elem + " " + elem.getClass().getCanonicalName());
|
trace.getErrorHandler().genericError(elem.getNode(), "Unsupported element in a block: " + elem + " " + elem.getClass().getCanonicalName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,15 +81,16 @@ public class ExpectedResolveData {
|
|||||||
|
|
||||||
public void checkResult(JetFile file) {
|
public void checkResult(JetFile file) {
|
||||||
final Set<PsiElement> unresolvedReferences = new HashSet<PsiElement>();
|
final Set<PsiElement> unresolvedReferences = new HashSet<PsiElement>();
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject(), new ErrorHandler() {
|
ErrorHandler errorHandler = new ErrorHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
|
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
|
||||||
unresolvedReferences.add(referenceExpression);
|
unresolvedReferences.add(referenceExpression);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject());
|
||||||
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
||||||
|
|
||||||
BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, semanticServices.getErrorHandler());
|
BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, errorHandler);
|
||||||
|
|
||||||
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
|
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet.types;
|
|||||||
|
|
||||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||||
import com.intellij.openapi.application.PathManager;
|
import com.intellij.openapi.application.PathManager;
|
||||||
import org.jetbrains.jet.lang.ErrorHandler;
|
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.psi.JetChangeUtil;
|
import org.jetbrains.jet.lang.psi.JetChangeUtil;
|
||||||
import org.jetbrains.jet.lang.psi.JetFunction;
|
import org.jetbrains.jet.lang.psi.JetFunction;
|
||||||
@@ -26,7 +25,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.DO_NOTHING);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
|||||||
import com.intellij.openapi.application.PathManager;
|
import com.intellij.openapi.application.PathManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.ErrorHandler;
|
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
|
||||||
import org.jetbrains.jet.lang.psi.JetChangeUtil;
|
import org.jetbrains.jet.lang.psi.JetChangeUtil;
|
||||||
@@ -32,7 +31,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
library = JetStandardLibrary.getJetStandardLibrary(getProject());
|
||||||
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.DO_NOTHING);
|
semanticServices = JetSemanticServices.createSemanticServices(library);
|
||||||
classDefinitions = new ClassDefinitions();
|
classDefinitions = new ClassDefinitions();
|
||||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user