Skip to content

Commit

Permalink
Unknown semantics: WIP update Unknown in generics
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jun 25, 2015
1 parent 3edbe2b commit 07c97a3
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
5 changes: 2 additions & 3 deletions hxcpp-debugger-protocol/hxcpp-debugger-protocol.iml
Expand Up @@ -3,10 +3,9 @@
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/JavaProtocol/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

</module>
Expand Up @@ -102,7 +102,7 @@ public ResultHolder getType() {
public ResultHolder getType(@Nullable HaxeGenericResolver resolver) {
if (resolver != null) {
ResultHolder resolved = resolver.resolve(getType(null).getType().toStringWithoutConstant());
if (resolved != null) return resolved.getType().createHolder();
if (resolved != null) return resolved;
}
return HaxeTypeResolver.getTypeFromTypeTag(getTypeTagPsi(), this.getContextElement());
}
Expand Down
Expand Up @@ -412,7 +412,7 @@ public void run() {
if (list1.isEmpty()) {
final PsiElement child = list.getFirstChild();
if ((child instanceof HaxeForStatement) || (child instanceof HaxeWhileStatement)) {
return SpecificTypeReference.createArray(handle(child, context).getType()).createHolder();
return SpecificTypeReference.createArray(handle(child, context)).createHolder();
}
}
}
Expand All @@ -431,9 +431,13 @@ public void run() {
references.add(type);
}
}
SpecificTypeReference result = SpecificHaxeClassReference.createArray(HaxeTypeUnifier.unify(references, element).withoutConstantValue());

ResultHolder elementTypeHolder = HaxeTypeUnifier.unify(references, element).withoutConstantValue().createHolder();

SpecificTypeReference result = SpecificHaxeClassReference.createArray(elementTypeHolder);
if (allConstants) result = result.withConstantValue(constants);
return result.createHolder();
ResultHolder holder = result.createHolder();
return holder;
}

if (element instanceof PsiJavaToken) {
Expand Down Expand Up @@ -664,7 +668,7 @@ static private void checkParameters(
ResultHolder value = handle(expression, context);

if (type.isUnknown()) {
type.setType(value.getType());
type.setType(value.getType().withoutConstantValue());
}

if (!type.canAssign(value)) {
Expand Down
Expand Up @@ -17,6 +17,7 @@
*/
package com.intellij.plugins.haxe.model.type;

import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -114,4 +115,9 @@ public ResultHolder duplicate() {
public ResultHolder withConstantValue(Object constantValue) {
return duplicate().setType(getType().withConstantValue(constantValue));
}


public PsiElement getElementContext() {
return type.getElementContext();
}
}
Expand Up @@ -32,9 +32,9 @@ static public SpecificTypeReference ensure(SpecificTypeReference clazz, @NotNull
return (clazz != null) ? clazz : getDynamic(context);
}

static public SpecificTypeReference createArray(@NotNull SpecificTypeReference elementType) {
static public SpecificTypeReference createArray(@NotNull ResultHolder elementType) {
return SpecificHaxeClassReference
.withGenerics(new HaxeClassReference("Array", elementType.context), new ResultHolder[]{elementType.createHolder()}, null);
.withGenerics(new HaxeClassReference("Array", elementType.getElementContext()), new ResultHolder[]{elementType}, null);
}

public SpecificTypeReference withRangeConstraint(HaxeRange range) {
Expand Down
8 changes: 8 additions & 0 deletions testData/annotation.semantic.body/UpdateUnknownInGenerics.hx
@@ -0,0 +1,8 @@
class Test {
public function test() {
var aaa = [];
aaa.push('test');
aaa.push(10);
return aaa;
}
}

0 comments on commit 07c97a3

Please sign in to comment.