Skip to content

Commit

Permalink
feat: scoping for member accesses if receiver has type parameter type (
Browse files Browse the repository at this point in the history
…#889)

### Summary of Changes

The scope provider can now handle member accesses where the receiver has
type parameter type. This type is replaced by its upper bound, before
name resolution continues as before.
  • Loading branch information
lars-reimann authored Feb 17, 2024
1 parent 83378a3 commit 1277bd1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {
} from '../helpers/nodeProperties.js';
import { SafeDsNodeMapper } from '../helpers/safe-ds-node-mapper.js';
import { SafeDsServices } from '../safe-ds-module.js';
import { ClassType, EnumVariantType, LiteralType } from '../typing/model.js';
import { ClassType, EnumVariantType, LiteralType, TypeParameterType } from '../typing/model.js';
import type { SafeDsClassHierarchy } from '../typing/safe-ds-class-hierarchy.js';
import { SafeDsTypeComputer } from '../typing/safe-ds-type-computer.js';
import { SafeDsPackageManager } from '../workspace/safe-ds-package-manager.js';
Expand Down Expand Up @@ -227,6 +227,8 @@ export class SafeDsScopeProvider extends DefaultScopeProvider {
let receiverType = this.typeComputer.computeType(node.receiver);
if (receiverType instanceof LiteralType) {
receiverType = this.typeComputer.computeClassTypeForLiteralType(receiverType);
} else if (receiverType instanceof TypeParameterType) {
receiverType = this.typeComputer.computeUpperBound(receiverType);
}

if (receiverType instanceof ClassType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package tests.scoping.memberAccesses.onTypeParameters

class C {
// $TEST$ target attribute
attr »a«: Int
}

class MyClass<Unbounded, UpperBound>(
unbounded: Unbounded,
upperBound: UpperBound,

// $TEST$ unresolved
p1: Any = unbounded.»a«,
// $TEST$ references attribute
p2: Any = upperBound.»a«,
) where {
UpperBound sub C
} {
attr unbounded: Unbounded
attr upperBound: UpperBound
}

segment mySegment(instance: MyClass<C, C>) {
// $TEST$ references attribute
instance.unbounded.»a«;

// $TEST$ references attribute
instance.upperBound.»a«;
}

0 comments on commit 1277bd1

Please sign in to comment.