Skip to content

Commit

Permalink
resolve type for parameters with only init expression
Browse files Browse the repository at this point in the history
  • Loading branch information
m0rkeulv committed Jan 29, 2024
1 parent 9735131 commit d06aeb8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,21 @@ public ResultHolder getType() {
if (typeReplacement != null) {
return typeReplacement.duplicate();
}
ResultHolder type = null;
HaxeTypeTag psi = getTypeTagPsi();
ResultHolder type = HaxeTypeResolver.getTypeFromTypeTag(psi, this.getContextElement());
//caching when we know there's no generics involved
if (!type.isTypeParameter() && type.getClassType() != null && type.getClassType().getSpecifics().length == 0 ) {
if (psi != null && psi.textMatches(type.getType().toString())) { // make sure we are not caching a resolved value (ex. param:T being resolved to param:String)
typeReplacement = type;
if (psi != null) {
type = HaxeTypeResolver.getTypeFromTypeTag(psi, this.getContextElement());
//caching when we know there's no generics involved
if (!type.isTypeParameter() && type.getClassType() != null && type.getClassType().getSpecifics().length == 0) {
if (psi.textMatches(type.getType().toString())) { // make sure we are not caching a resolved value (ex. param:T being resolved to param:String)
typeReplacement = type;
}
}
}else if (this.getVarInitPsi() != null) {
type = HaxeExpressionEvaluator.evaluate(this.getVarInitPsi(), null).result;
}else {
type = new ResultHolder(SpecificHaxeClassReference.getUnknown(this.basePsi));
}

return type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,9 @@ else if (subelement instanceof HaxeLocalFunctionDeclaration functionDeclaration)

else if (subelement instanceof AbstractHaxeNamedComponent namedComponent) {
typeHolder = HaxeTypeResolver.getFieldOrMethodReturnType(namedComponent, resolver);
} else {
// unable to find type
typeHolder = SpecificTypeReference.getUnknown(element).createHolder();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,10 @@ public void testMissingInterfaceMethodsOnConstrainedGenericOverrides() throws Ex
// doTestNoFixWithWarnings();
//}

@Test
public void testNoErrorOnOptionalParameterWithFieldConstant() throws Exception {
doTestNoFixWithWarnings();
}
@Test
public void testNoErrorOnOptionalParameterWithIntFieldConstant() throws Exception {
doTestNoFixWithWarnings();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package;

class Test {
static inline var myConstant:Int = 4;

public function someFunction(param = myConstant):Void {

}

public function new() {
someFunction();
someFunction(1);
someFunction(<error descr="Type mismatch (Expected: 'Int' got: 'String')">""</error>);// Wrong: incorrect parameter type
}
}

0 comments on commit d06aeb8

Please sign in to comment.