diff --git a/src/main/java/leekscript/compiler/expression/LeekFunctionCall.java b/src/main/java/leekscript/compiler/expression/LeekFunctionCall.java index 707ecdc..26628fc 100644 --- a/src/main/java/leekscript/compiler/expression/LeekFunctionCall.java +++ b/src/main/java/leekscript/compiler/expression/LeekFunctionCall.java @@ -539,9 +539,9 @@ else if (!mExpression.getType().canBeCallable()) { if (count == mParameters.size()) { var staticMethod = methods.get(count); if (staticMethod.level == AccessLevel.PRIVATE && compiler.getCurrentClass() != clazz) { - compiler.addError(new AnalyzeError(oa.getFieldToken(), AnalyzeErrorLevel.ERROR, Error.PRIVATE_STATIC_METHOD, new String[] { clazz.getName(), oa.getField() })); + compiler.addError(new AnalyzeError(oa.getLastToken(), AnalyzeErrorLevel.ERROR, Error.PRIVATE_STATIC_METHOD, new String[] { clazz.getName(), oa.getField() })); } else if (staticMethod.level == AccessLevel.PROTECTED && (compiler.getCurrentClass() == null || !compiler.getCurrentClass().descendsFrom(clazz))) { - compiler.addError(new AnalyzeError(oa.getFieldToken(), AnalyzeErrorLevel.ERROR, Error.PROTECTED_STATIC_METHOD, new String[] { clazz.getName(), oa.getField() })); + compiler.addError(new AnalyzeError(oa.getLastToken(), AnalyzeErrorLevel.ERROR, Error.PROTECTED_STATIC_METHOD, new String[] { clazz.getName(), oa.getField() })); } is_static_method = true; method = staticMethod; @@ -562,13 +562,13 @@ else if (!mExpression.getType().canBeCallable()) { var field = clazz.getStaticField(oa.getField()); if (field != null) { if (field.level == AccessLevel.PRIVATE && compiler.getCurrentClass() != clazz) { - compiler.addError(new AnalyzeError(oa.getFieldToken(), AnalyzeErrorLevel.ERROR, Error.PRIVATE_STATIC_FIELD, new String[] { clazz.getName(), oa.getField() })); + compiler.addError(new AnalyzeError(oa.getLastToken(), AnalyzeErrorLevel.ERROR, Error.PRIVATE_STATIC_FIELD, new String[] { clazz.getName(), oa.getField() })); } else if (field.level == AccessLevel.PROTECTED && (compiler.getCurrentClass() == null || !compiler.getCurrentClass().descendsFrom(clazz))) { - compiler.addError(new AnalyzeError(oa.getFieldToken(), AnalyzeErrorLevel.ERROR, Error.PROTECTED_STATIC_FIELD, new String[] { clazz.getName(), oa.getField() })); + compiler.addError(new AnalyzeError(oa.getLastToken(), AnalyzeErrorLevel.ERROR, Error.PROTECTED_STATIC_FIELD, new String[] { clazz.getName(), oa.getField() })); } is_static_method = true; } else { - compiler.addError(new AnalyzeError(oa.getFieldToken(), AnalyzeErrorLevel.ERROR, Error.CLASS_STATIC_MEMBER_DOES_NOT_EXIST, new String[] { clazz.getName(), oa.getField() })); + compiler.addError(new AnalyzeError(oa.getLastToken(), AnalyzeErrorLevel.ERROR, Error.CLASS_STATIC_MEMBER_DOES_NOT_EXIST, new String[] { clazz.getName(), oa.getField() })); } } } diff --git a/src/main/java/leekscript/compiler/expression/LeekObjectAccess.java b/src/main/java/leekscript/compiler/expression/LeekObjectAccess.java index 67a1e12..7e6a039 100644 --- a/src/main/java/leekscript/compiler/expression/LeekObjectAccess.java +++ b/src/main/java/leekscript/compiler/expression/LeekObjectAccess.java @@ -183,7 +183,7 @@ public void analyze(WordCompiler compiler) throws LeekCompilerException { } public String getField() { - return field.getWord(); + return field == null ? "" : field.getWord(); } public Token getFieldToken() { @@ -492,7 +492,7 @@ public Hover hover(Token token) { } } var clazz = object.getType().getClassDeclaration(); - if (clazz != null) { + if (clazz != null && field != null) { var member = clazz.getMember(field.getWord()); if (member != null) { return new Hover(member.getType(), getLocation(), member.getLocation()); @@ -515,4 +515,15 @@ public Complete complete(Token token) { public LeekVariable getVariable() { return this.variable; } + + public Token getDot() { + return this.dot; + } + + public Token getLastToken() { + if (this.field != null) { + return this.field; + } + return this.dot; + } }