Skip to content

Commit 7cd48f8

Browse files
committed
WIP: TASK Simplify MatchTypeResolver::resolveTypeOfEnumMatch
1 parent e56b821 commit 7cd48f8

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/TypeSystem/Resolver/Match/MatchTypeResolver.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@
2222

2323
namespace PackageFactory\ComponentEngine\TypeSystem\Resolver\Match;
2424

25-
use PackageFactory\ComponentEngine\Parser\Ast\AccessNode;
2625
use PackageFactory\ComponentEngine\Parser\Ast\BooleanLiteralNode;
2726
use PackageFactory\ComponentEngine\Parser\Ast\MatchNode;
28-
use PackageFactory\ComponentEngine\TypeSystem\Resolver\Access\AccessTypeResolver;
2927
use PackageFactory\ComponentEngine\TypeSystem\Resolver\Expression\ExpressionTypeResolver;
3028
use PackageFactory\ComponentEngine\TypeSystem\ScopeInterface;
3129
use PackageFactory\ComponentEngine\TypeSystem\Type\BooleanType\BooleanType;
3230
use PackageFactory\ComponentEngine\TypeSystem\Type\EnumType\EnumMemberType;
33-
use PackageFactory\ComponentEngine\TypeSystem\Type\EnumType\EnumStaticType;
3431
use PackageFactory\ComponentEngine\TypeSystem\Type\EnumType\EnumType;
3532
use PackageFactory\ComponentEngine\TypeSystem\Type\UnionType\UnionType;
3633
use PackageFactory\ComponentEngine\TypeSystem\TypeInterface;
@@ -97,8 +94,6 @@ private function resolveTypeOfEnumMatch(MatchNode $matchNode, EnumType $subjectE
9794
);
9895
$types = [];
9996

100-
$accessTypeResolver = new AccessTypeResolver(scope: $this->scope);
101-
10297
$defaultArmPresent = false;
10398
$referencedEnumMembers = [];
10499

@@ -110,14 +105,9 @@ private function resolveTypeOfEnumMatch(MatchNode $matchNode, EnumType $subjectE
110105
$defaultArmPresent = true;
111106
} else {
112107
foreach ($matchArmNode->left->items as $expressionNode) {
113-
$accessNode = $expressionNode->root;
114-
if (!$accessNode instanceof AccessNode
115-
|| !($enumMemberType = $accessTypeResolver->resolveTypeOf($accessNode)) instanceof EnumMemberType) {
116-
throw new \Error('@TODO Error: To be matched enum value should be referenced like: `Enum.B`');
117-
}
118-
119-
if (!$enumMemberType->enumType instanceof EnumStaticType) {
120-
throw new \Exception('@TODO Error: To be matched enum must be referenced static');
108+
$enumMemberType = $expressionTypeResolver->resolveTypeOf($expressionNode);
109+
if (!$enumMemberType instanceof EnumMemberType) {
110+
throw new \Error('@TODO Error: Cannot match enum with type of ' . $enumMemberType::class);
121111
}
122112

123113
if (!$enumMemberType->enumType->is($subjectEnumType)) {

test/Unit/TypeSystem/Resolver/Match/MatchTypeResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function malformedEnumExamples(): iterable
188188
"foo" -> "a"
189189
}
190190
EOF,
191-
"@TODO Error: To be matched enum value should be referenced like: `Enum.B`"
191+
"@TODO Error: Cannot match enum with type of PackageFactory\ComponentEngine\TypeSystem\Type\StringType\StringType"
192192
];
193193
}
194194

0 commit comments

Comments
 (0)