Skip to content
Permalink
Browse files

Fix access on matched T[K]

  • Loading branch information...
muglug committed May 27, 2019
1 parent 2eae790 commit cf02e9c22c912476b41210f210b39e6e2c50d912
@@ -488,8 +488,6 @@ public static function getArrayAccessTypeGivenOffset(
if ($offset_as instanceof Type\Atomic\TTemplateKeyOf
&& $offset_as->param_name === $original_type->param_name
&& $offset_as->defining_class === $original_type->defining_class
&& $offset_atomic_type->defining_class
=== $original_type->defining_class
) {
$type->type_params[1] = new Type\Union([
new Type\Atomic\TTemplateIndexedAccess(
@@ -189,6 +189,7 @@ public static function create(
if (isset($template_type_map[$value])) {
$first_class = array_keys($template_type_map[$value])[0];
return new TTemplateParam(
$value,
$template_type_map[$value][$first_class][0],
@@ -2373,7 +2373,7 @@ function getOffset(array $o, $name) {
'$c' => 'int',
]
],
'keyOfClassTemplate' => [
'keyOfClassTemplateAcceptingIndexedAccess' => [
'<?php
/**
* @template TData as array
@@ -2392,20 +2392,43 @@ public function __construct(array $data) {
}
/**
* @param key-of<TData> $property
* @template K as key-of<TData>
*
* @param K $property
* @param TData[K] $value
*/
public function __get(string $property) {
return $this->data[$property] ?? null;
public function __set(string $property, $value) {
$this->data[$property] = $value;
}
}'
],
'keyOfClassTemplateReturningIndexedAccess' => [
'<?php
/**
* @template TData as array
*/
abstract class DataBag {
/**
* @var TData
*/
protected $data;
/**
* @param TData $data
*/
public function __construct(array $data) {
$this->data = $data;
}
/**
* @template K as key-of<TData>
*
* @param K $property
* @param TData[K] $value
*
* @return TData[K]
*/
public function __set(string $property, $value) {
$this->data[$property] = $value;
public function __get(string $property) {
return $this->data[$property];
}
}'
],

0 comments on commit cf02e9c

Please sign in to comment.
You can’t perform that action at this time.