fix resolving of class type variables

This commit is contained in:
Dave Holoway
2020-06-16 18:50:35 +01:00
parent 26e54bba37
commit 8df1a3464b

View File

@@ -274,36 +274,39 @@ function resolveTypeOrPackage(ident, type_variables, scope, imports, typemap) {
types.push(tv.type); types.push(tv.type);
} }
if (!types[0] && scope instanceof MethodBase) { if (scope) {
// is it a type variable in the current scope
const tv = scope.typeVariables.find(tv => tv.name === ident);
if (tv) {
types.push(tv.type);
}
}
if (!types[0] && scope) { if (!types[0] && scope instanceof MethodBase) {
// is it an enclosed type of the currently scoped type or any outer type // is it a type variable in the current scope
const scoped_type = scope instanceof CEIType ? scope : scope.owner; const tv = scope.typeVariables.find(tv => tv.name === ident);
const scopes = scoped_type.shortSignature.split('$'); if (tv) {
while (scopes.length) { types.push(tv.type);
const enc_type = typemap.get(`${scopes.join('$')}$${ident}`);
if (enc_type) {
types.push(enc_type);
break;
} }
scopes.pop();
} }
if (!types[0] && scoped_type.simpleTypeName === ident) {
types.push(scoped_type);
}
}
if (!types[0] && scope instanceof CEIType) { const scoped_type = scope instanceof CEIType ? scope : scope.owner;
// is it a type variable of the currently scoped type if (!types[0]) {
const tv = scope.typeVariables.find(tv => tv.name === ident); // is it an enclosed type of the currently scoped type or any outer type
if (tv) { const scopes = scoped_type.shortSignature.split('$');
types.push(tv.type); while (scopes.length) {
const enc_type = typemap.get(`${scopes.join('$')}$${ident}`);
if (enc_type) {
types.push(enc_type);
break;
}
scopes.pop();
}
if (!types[0] && scoped_type.simpleTypeName === ident) {
types.push(scoped_type);
}
}
if (!types[0]) {
// is it a type variable of the currently scoped type
const tv = scoped_type.typeVariables.find(tv => tv.name === ident);
if (tv) {
types.push(tv.type);
}
} }
} }