11
11
use PHPStan \Reflection \Php \PhpMethodFromParserNodeReflection ;
12
12
use PHPStan \Rules \RuleErrorBuilder ;
13
13
use PHPStan \TrinaryLogic ;
14
+ use PHPStan \Type \Generic \TemplateTypeHelper ;
14
15
use PHPStan \Type \MixedType ;
15
16
use PHPStan \Type \Type ;
16
17
use PHPStan \Type \TypehintHelper ;
@@ -154,11 +155,11 @@ private function checkReturnTypeCompatibility(
154
155
{
155
156
$ returnType = TypehintHelper::decideType (
156
157
$ currentVariant ->getNativeReturnType (),
157
- $ currentVariant ->getPhpDocReturnType ()
158
+ TemplateTypeHelper:: resolveToBounds ( $ currentVariant ->getPhpDocReturnType () )
158
159
);
159
160
$ parentReturnType = TypehintHelper::decideType (
160
161
$ parentVariant ->getNativeReturnType (),
161
- $ parentVariant ->getPhpDocReturnType ()
162
+ TemplateTypeHelper:: resolveToBounds ( $ parentVariant ->getPhpDocReturnType () )
162
163
);
163
164
// Allow adding `void` return type hints when the parent defines no return type
164
165
if ($ returnType instanceof VoidType && $ parentReturnType instanceof MixedType) {
@@ -170,7 +171,10 @@ private function checkReturnTypeCompatibility(
170
171
return [TrinaryLogic::createYes (), $ returnType , $ parentReturnType ];
171
172
}
172
173
173
- return [$ parentReturnType ->isSuperTypeOf ($ returnType ), $ returnType , $ parentReturnType ];
174
+ return [$ parentReturnType ->isSuperTypeOf ($ returnType ), TypehintHelper::decideType (
175
+ $ currentVariant ->getNativeReturnType (),
176
+ $ currentVariant ->getPhpDocReturnType ()
177
+ ), $ parentReturnType ];
174
178
}
175
179
176
180
/**
@@ -192,14 +196,17 @@ private function checkParameterTypeCompatibility(
192
196
193
197
$ parameterType = TypehintHelper::decideType (
194
198
$ parameter ->getNativeType (),
195
- $ parameter ->getPhpDocType ()
199
+ TemplateTypeHelper:: resolveToBounds ( $ parameter ->getPhpDocType () )
196
200
);
197
201
$ parentParameterType = TypehintHelper::decideType (
198
202
$ parentParameter ->getNativeType (),
199
- $ parentParameter ->getPhpDocType ()
203
+ TemplateTypeHelper:: resolveToBounds ( $ parentParameter ->getPhpDocType () )
200
204
);
201
205
202
- $ parameterResults [] = [$ parameterType ->isSuperTypeOf ($ parentParameterType ), $ parameterType , $ parentParameterType ];
206
+ $ parameterResults [] = [$ parameterType ->isSuperTypeOf ($ parentParameterType ), TypehintHelper::decideType (
207
+ $ parameter ->getNativeType (),
208
+ $ parameter ->getPhpDocType ()
209
+ ), $ parentParameterType ];
203
210
}
204
211
205
212
return $ parameterResults ;
0 commit comments