Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -812,8 +812,9 @@ protected Optional<SymTypeExpression> calculateExprFieldAccess(
type = Optional.empty();
}
else {
SymTypeExpression innerAsExprType =
getType4Ast().getPartialTypeOfExpr(expr.getExpression());
SymTypeExpression innerAsExprType = SymTypeRelations.normalize(
getType4Ast().getPartialTypeOfExpr(expr.getExpression())
);
if (WithinTypeBasicSymbolsResolver.canResolveIn(innerAsExprType)) {
AccessModifier modifier = innerAsExprType.hasTypeInfo() ?
TypeContextCalculator.getAccessModifier(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ protected List<SymTypeOfFunction> _resolveConstructors(
}

// do not search super types for constructors

List<SymTypeOfFunction> symTypesFreeVarsReplaced = resolvedSymTypes.stream()
.map(this::replaceFreeConstructorTypeVariables)
.map(SymTypeExpression::asFunctionType)
.collect(Collectors.toList());

return symTypesFreeVarsReplaced;
}

Expand Down Expand Up @@ -140,7 +140,7 @@ protected SymTypeExpression replaceFreeConstructorTypeVariables(SymTypeExpressio

return typeVarsReplaced;
}

protected boolean isConstructor(FunctionSymbol func) {
if (OOSymbolsMill.typeDispatcher().isOOSymbolsMethod(func)) {
MethodSymbol method = OOSymbolsMill.typeDispatcher().asOOSymbolsMethod(func);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ protected Optional<SymTypeExpression> _resolveVariable(
String name,
AccessModifier accessModifier,
Predicate<VariableSymbol> predicate) {
return resolveVariableRecursive(thisType, name, accessModifier, predicate);
}

protected Optional<SymTypeExpression> resolveVariableRecursive(
SymTypeExpression thisType,
String name,
AccessModifier accessModifier,
Predicate<VariableSymbol> predicate) {
Optional<SymTypeExpression> resolvedSymType;
Optional<IBasicSymbolsScope> spannedScopeOpt = getSpannedScope(thisType);
if (spannedScopeOpt.isEmpty()) {
Expand Down Expand Up @@ -103,11 +111,16 @@ protected Optional<SymTypeExpression> _resolveVariable(
resolvedSymType = Optional.empty();
for (SymTypeExpression superType : superTypes) {
Optional<SymTypeExpression> resolvedInSuper =
resolveVariable(superType, name, superModifier, predicate);
resolveVariableRecursive(superType, name, superModifier, predicate);
if (resolvedSymType.isPresent() && resolvedInSuper.isPresent()) {
Log.error("0xFD222 found variables with name \""
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"");
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"."
+ " Nominal super types:"
+ superTypes.stream().map(st ->
System.lineSeparator() + st.printFullName()
)
);
}
else if (resolvedSymType.isEmpty() && resolvedInSuper.isPresent()) {
resolvedSymType = resolvedInSuper;
Expand Down Expand Up @@ -177,6 +190,15 @@ protected List<SymTypeOfFunction> _resolveFunctions(
String name,
AccessModifier accessModifier,
Predicate<FunctionSymbol> predicate
) {
return resolveFunctionsRecursive(thisType, name, accessModifier, predicate);
}

protected List<SymTypeOfFunction> resolveFunctionsRecursive(
SymTypeExpression thisType,
String name,
AccessModifier accessModifier,
Predicate<FunctionSymbol> predicate
) {
List<SymTypeOfFunction> resolvedSymTypes = new ArrayList<>();
List<SymTypeOfFunction> resolvedInThis =
Expand Down Expand Up @@ -254,7 +276,7 @@ protected List<SymTypeOfFunction> resolvedFunctionsInSuperTypes(
List<SymTypeOfFunction> superFuncs = new ArrayList<>();
for (SymTypeExpression superType : superTypes) {
List<SymTypeOfFunction> resolvedInSuper =
resolveFunctions(superType, name, superModifier, predicate);
resolveFunctionsRecursive(superType, name, superModifier, predicate);
superFuncs.addAll(resolvedInSuper);
}
// filter based on being inherited twice (diamond pattern)
Expand Down Expand Up @@ -321,6 +343,14 @@ protected Optional<SymTypeExpression> _resolveType(
String name,
AccessModifier accessModifier,
Predicate<TypeSymbol> predicate) {
return resolveTypeRecursive(thisType, name, accessModifier, predicate);
}

protected Optional<SymTypeExpression> resolveTypeRecursive(
SymTypeExpression thisType,
String name,
AccessModifier accessModifier,
Predicate<TypeSymbol> predicate) {
Optional<SymTypeExpression> resolvedSymType;
Optional<IBasicSymbolsScope> spannedScopeOpt = getSpannedScope(thisType);
if (spannedScopeOpt.isEmpty()) {
Expand Down Expand Up @@ -354,11 +384,16 @@ protected Optional<SymTypeExpression> _resolveType(
resolvedSymType = Optional.empty();
for (SymTypeExpression superType : superTypes) {
Optional<SymTypeExpression> resolvedInSuper =
resolveType(superType, name, superModifier, predicate);
resolveTypeRecursive(superType, name, superModifier, predicate);
if (resolvedSymType.isPresent() && resolvedInSuper.isPresent()) {
Log.error("0xFD224 found type with name \""
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"");
+ name + "\" in multiple super types of \""
+ thisType.printFullName() + "\"."
+ " Nominal super types:"
+ superTypes.stream().map(st ->
System.lineSeparator() + st.printFullName()
)
);
}
resolvedSymType = resolvedInSuper;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1725,6 +1725,11 @@ public void init_advanced() {
SymTypeExpressionFactory.createTypeExpression(oneFieldMember));
firstLayer.setIsStatic(true);
inScope(deepNesting.getSpannedScope(), firstLayer);

// specifically not normalized intersection
inScope(globalScope, variable("intersectionNotNormalized",
createIntersection(createTypeObject(testType), createTypeObject(testType))
));
}

@Test
Expand Down Expand Up @@ -1782,6 +1787,16 @@ public void deriveFromFieldAccessExpressionInnerResults() throws IOException {
assertNoFindings();
}

/**
* tests whether intersection types are properly supported
*/
@Test
public void deriveFromFieldAccessExpressionDoubleIntersection() {
init_advanced();

checkExpr("intersectionNotNormalized.variable", "int");
}

/**
* tests whether inner results are all present
*/
Expand Down
Loading