fix(DefinitionResolver): fix methods with self return type (#550)
parent
9eea26df71
commit
63da051e72
|
@ -729,7 +729,7 @@ class DefinitionResolver
|
||||||
foreach ($classDef->getAncestorDefinitions($this->index, true) as $fqn => $def) {
|
foreach ($classDef->getAncestorDefinitions($this->index, true) as $fqn => $def) {
|
||||||
$def = $this->index->getDefinition($fqn . $add);
|
$def = $this->index->getDefinition($fqn . $add);
|
||||||
if ($def !== null) {
|
if ($def !== null) {
|
||||||
if ($def->type instanceof Types\This) {
|
if ($def->type instanceof Types\This || $def->type instanceof Types\Self_) {
|
||||||
return new Types\Object_(new Fqsen('\\' . $classFqn));
|
return new Types\Object_(new Fqsen('\\' . $classFqn));
|
||||||
}
|
}
|
||||||
return $def->type;
|
return $def->type;
|
||||||
|
@ -1090,6 +1090,12 @@ class DefinitionResolver
|
||||||
if ($node->returnType instanceof PhpParser\Token) {
|
if ($node->returnType instanceof PhpParser\Token) {
|
||||||
// Resolve a string like "bool" to a type object
|
// Resolve a string like "bool" to a type object
|
||||||
return $this->typeResolver->resolve($node->returnType->getText($node->getFileContents()));
|
return $this->typeResolver->resolve($node->returnType->getText($node->getFileContents()));
|
||||||
|
} elseif ($node->returnType->getResolvedName() === 'self') {
|
||||||
|
$classNode = $node->getFirstAncestor(Node\Statement\ClassDeclaration::class);
|
||||||
|
if ($classNode) {
|
||||||
|
$classFqn = (string)$classNode->getNamespacedName();
|
||||||
|
return new Types\Object_(new Fqsen('\\' . $classFqn));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new Types\Object_(new Fqsen('\\' . (string)$node->returnType->getResolvedName()));
|
return new Types\Object_(new Fqsen('\\' . (string)$node->returnType->getResolvedName()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@
|
||||||
},
|
},
|
||||||
"containerName": "Fixtures\\Prophecy\\WithReturnTypehints"
|
"containerName": "Fixtures\\Prophecy\\WithReturnTypehints"
|
||||||
},
|
},
|
||||||
"type__tostring": "\\self",
|
"type__tostring": "\\Fixtures\\Prophecy\\WithReturnTypehints",
|
||||||
"type": {},
|
"type": {},
|
||||||
"declarationLine": "public function getSelf(): self {",
|
"declarationLine": "public function getSelf(): self {",
|
||||||
"documentation": null,
|
"documentation": null,
|
||||||
|
|
|
@ -5,5 +5,7 @@ class FooClass {
|
||||||
return new FooClass();
|
return new FooClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function staticSelf(): self { }
|
||||||
|
|
||||||
public function bar() { }
|
public function bar() { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,31 @@
|
||||||
"parameters": []
|
"parameters": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"FooClass::staticSelf()": {
|
||||||
|
"fqn": "FooClass::staticSelf()",
|
||||||
|
"extends": [],
|
||||||
|
"isMember": true,
|
||||||
|
"roamed": false,
|
||||||
|
"isStatic": true,
|
||||||
|
"canBeInstantiated": false,
|
||||||
|
"symbolInformation": {
|
||||||
|
"name": "staticSelf",
|
||||||
|
"kind": 6,
|
||||||
|
"location": {
|
||||||
|
"uri": "./staticMethodReturnType.php"
|
||||||
|
},
|
||||||
|
"containerName": "FooClass"
|
||||||
|
},
|
||||||
|
"type__tostring": "\\FooClass",
|
||||||
|
"type": {},
|
||||||
|
"declarationLine": "public static function staticSelf(): self { }",
|
||||||
|
"documentation": null,
|
||||||
|
"signatureInformation": {
|
||||||
|
"label": "()",
|
||||||
|
"documentation": null,
|
||||||
|
"parameters": []
|
||||||
|
}
|
||||||
|
},
|
||||||
"FooClass->bar()": {
|
"FooClass->bar()": {
|
||||||
"fqn": "FooClass->bar()",
|
"fqn": "FooClass->bar()",
|
||||||
"extends": [],
|
"extends": [],
|
||||||
|
|
Loading…
Reference in New Issue