Fixed #155: Add missing declared type for "self" or "cls" parameters in methods so the hover provider reports the correct inferred type.

This commit is contained in:
Eric Traut 2019-06-21 12:33:05 -06:00
parent ed4f87a4c9
commit 6c25035b1d

View File

@ -436,22 +436,21 @@ export class TypeAnalyzer extends ParseTreeWalker {
parameters.forEach((param, index) => { parameters.forEach((param, index) => {
const paramNode = node.parameters[index]; const paramNode = node.parameters[index];
if (paramNode.name) { if (paramNode.name) {
const specializedParamType = TypeUtils.specializeType(param.type, undefined);
let declaration: Declaration | undefined; let declaration: Declaration | undefined;
declaration = { declaration = {
category: SymbolCategory.Parameter, category: SymbolCategory.Parameter,
node: paramNode, node: paramNode,
path: this._fileInfo.filePath, path: this._fileInfo.filePath,
range: convertOffsetsToRange(paramNode.start, paramNode.end, this._fileInfo.lines), range: convertOffsetsToRange(paramNode.start, paramNode.end, this._fileInfo.lines),
declaredType: paramNode.typeAnnotation ? declaredType: specializedParamType
TypeUtils.specializeType(param.type, undefined) :
undefined
}; };
assert(paramNode !== undefined && paramNode.name !== undefined); assert(paramNode !== undefined && paramNode.name !== undefined);
// If the type contains type variables, specialize them now // If the type contains type variables, specialize them now
// so we convert them to a concrete type (or unknown if there // so we convert them to a concrete type (or unknown if there
// are is no bound or contraints). // is no bound or contraint).
const specializedParamType = TypeUtils.specializeType(param.type, undefined);
const variadicParamType = this._getVariadicParamType(param.category, specializedParamType); const variadicParamType = this._getVariadicParamType(param.category, specializedParamType);
this._addTypeSourceToNameNode(paramNode.name, variadicParamType, declaration); this._addTypeSourceToNameNode(paramNode.name, variadicParamType, declaration);