Skip to content

Commit 6559c40

Browse files
committed
Type : Remove traces from types
1 parent f161b4c commit 6559c40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+143
-381
lines changed

src/Psl/Type/Exception/AssertException.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ final class AssertException extends Exception
1212
{
1313
private string $expected;
1414

15-
public function __construct(string $actual, string $expected, TypeTrace $typeTrace)
15+
public function __construct(string $actual, string $expected)
1616
{
17-
parent::__construct(Str\format('Expected "%s", got "%s".', $expected, $actual), $actual, $typeTrace);
17+
parent::__construct(Str\format('Expected "%s", got "%s".', $expected, $actual), $actual);
1818

1919
$this->expected = $expected;
2020
}
@@ -27,8 +27,7 @@ public function getExpectedType(): string
2727
public static function withValue(
2828
mixed $value,
2929
string $expected_type,
30-
TypeTrace $trace
3130
): self {
32-
return new self(get_debug_type($value), $expected_type, $trace);
31+
return new self(get_debug_type($value), $expected_type);
3332
}
3433
}

src/Psl/Type/Exception/CoercionException.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class CoercionException extends Exception
1313
{
1414
private string $target;
1515

16-
public function __construct(string $actual, string $target, TypeTrace $typeTrace, string $additionalInfo = '')
16+
public function __construct(string $actual, string $target, string $additionalInfo = '')
1717
{
1818
parent::__construct(
1919
Str\format(
@@ -24,7 +24,6 @@ public function __construct(string $actual, string $target, TypeTrace $typeTrace
2424
$additionalInfo
2525
),
2626
$actual,
27-
$typeTrace,
2827
);
2928

3029
$this->target = $target;
@@ -38,21 +37,18 @@ public function getTargetType(): string
3837
public static function withValue(
3938
mixed $value,
4039
string $target,
41-
TypeTrace $typeTrace
4240
): self {
43-
return new self(get_debug_type($value), $target, $typeTrace);
41+
return new self(get_debug_type($value), $target);
4442
}
4543

4644
public static function withConversionFailureOnValue(
4745
mixed $value,
4846
string $target,
49-
TypeTrace $typeTrace,
5047
Throwable $failure,
5148
): self {
5249
return new self(
5350
get_debug_type($value),
5451
$target,
55-
$typeTrace,
5652
$failure->getMessage()
5753
);
5854
}

src/Psl/Type/Exception/Exception.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,19 @@
88

99
abstract class Exception extends RuntimeException implements ExceptionInterface
1010
{
11-
private TypeTrace $typeTrace;
1211
private string $actual;
1312

1413
public function __construct(
1514
string $message,
1615
string $actual,
17-
TypeTrace $typeTrace
1816
) {
1917
parent::__construct($message);
2018

2119
$this->actual = $actual;
22-
$this->typeTrace = $typeTrace;
2320
}
2421

2522
public function getActualType(): string
2623
{
2724
return $this->actual;
2825
}
29-
30-
public function getTypeTrace(): TypeTrace
31-
{
32-
return $this->typeTrace;
33-
}
3426
}

src/Psl/Type/Exception/TypeTrace.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Psl/Type/Internal/BackedEnumType.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,21 @@ public function coerce(mixed $value): BackedEnum
4343

4444
foreach (($this->enum)::cases() as $case) {
4545
if (Type\string()->matches($case->value)) {
46-
$string_value = Type\string()->withTrace($this->getTrace())->coerce($value);
46+
$string_value = Type\string()->coerce($value);
4747

4848
if ($string_value === $case->value) {
4949
return $case;
5050
}
5151
} else {
52-
$integer_value = Type\int()->withTrace($this->getTrace())->coerce($value);
52+
$integer_value = Type\int()->coerce($value);
5353

5454
if ($integer_value === $case->value) {
5555
return $case;
5656
}
5757
}
5858
}
5959

60-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
60+
throw CoercionException::withValue($value, $this->toString());
6161
}
6262

6363
/**
@@ -73,7 +73,7 @@ public function assert(mixed $value): BackedEnum
7373
return $value;
7474
}
7575

76-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
76+
throw AssertException::withValue($value, $this->toString());
7777
}
7878

7979
public function toString(): string

src/Psl/Type/Internal/BoolType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function coerce(mixed $value): bool
4242
return true;
4343
}
4444

45-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
45+
throw CoercionException::withValue($value, $this->toString());
4646
}
4747

4848
/**
@@ -56,7 +56,7 @@ public function assert(mixed $value): bool
5656
return $value;
5757
}
5858

59-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
59+
throw AssertException::withValue($value, $this->toString());
6060
}
6161

6262
public function toString(): string

src/Psl/Type/Internal/ClassStringType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function coerce(mixed $value): string
5050
return $value;
5151
}
5252

53-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
53+
throw CoercionException::withValue($value, $this->toString());
5454
}
5555

5656
/**
@@ -66,7 +66,7 @@ public function assert(mixed $value): string
6666
return $value;
6767
}
6868

69-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
69+
throw AssertException::withValue($value, $this->toString());
7070
}
7171

7272
public function toString(): string

src/Psl/Type/Internal/ConvertedType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function coerce(mixed $value): mixed
5353
try {
5454
$converted = ($this->converter)($coercedInput);
5555
} catch (Throwable $failure) {
56-
throw CoercionException::withConversionFailureOnValue($value, $this->toString(), $this->getTrace(), $failure);
56+
throw CoercionException::withConversionFailureOnValue($value, $this->toString(), $failure);
5757
}
5858

5959
return $this->into->coerce($converted);

src/Psl/Type/Internal/DictType.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ public function __construct(
3939
public function coerce(mixed $value): array
4040
{
4141
if (! is_iterable($value)) {
42-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
42+
throw CoercionException::withValue($value, $this->toString());
4343
}
4444

45-
$trace = $this->getTrace();
46-
$key_type = $this->key_type->withTrace($trace->withFrame('dict<' . $this->key_type->toString() . ', _>'));
47-
$value_type = $this->value_type->withTrace($trace->withFrame('dict<_, ' . $this->value_type->toString() . '>'));
45+
$key_type = $this->key_type;
46+
$value_type = $this->value_type;
4847

4948
$result = [];
5049

@@ -69,16 +68,11 @@ public function coerce(mixed $value): array
6968
public function assert(mixed $value): array
7069
{
7170
if (! is_array($value)) {
72-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
71+
throw AssertException::withValue($value, $this->toString());
7372
}
7473

75-
$trace = $this->getTrace();
76-
$key_type = $this->key_type->withTrace(
77-
$trace->withFrame('dict<' . $this->key_type->toString() . ', _>')
78-
);
79-
$value_type = $this->value_type->withTrace(
80-
$trace->withFrame('dict<_, ' . $this->value_type->toString() . '>')
81-
);
74+
$key_type = $this->key_type;
75+
$value_type = $this->value_type;
8276

8377
$result = [];
8478

src/Psl/Type/Internal/F32Type.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public function matches(mixed $value): bool
3939
*/
4040
public function coerce(mixed $value): float
4141
{
42-
$float = Type\float()
43-
->withTrace($this->getTrace()->withFrame($this->toString()))
44-
->coerce($value);
42+
$float = Type\float()->coerce($value);
4543

4644
if ($float >= MATH\FLOAT32_MIN && $float <= MATH\FLOAT32_MAX) {
4745
return $float;
4846
}
4947

50-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
48+
throw CoercionException::withValue($value, $this->toString());
5149
}
5250

5351
/**
@@ -67,7 +65,7 @@ public function assert(mixed $value): float
6765
return $value;
6866
}
6967

70-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
68+
throw AssertException::withValue($value, $this->toString());
7169
}
7270

7371
public function toString(): string

src/Psl/Type/Internal/F64Type.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public function matches(mixed $value): bool
3838
*/
3939
public function coerce(mixed $value): float
4040
{
41-
return Type\float()
42-
->withTrace($this->getTrace()->withFrame($this->toString()))
43-
->coerce($value);
41+
return Type\float()->coerce($value);
4442
}
4543

4644
/**

src/Psl/Type/Internal/FloatType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function coerce(mixed $value): float
5555
}
5656
}
5757

58-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
58+
throw CoercionException::withValue($value, $this->toString());
5959
}
6060

6161
/**
@@ -69,7 +69,7 @@ public function assert(mixed $value): float
6969
return $value;
7070
}
7171

72-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
72+
throw AssertException::withValue($value, $this->toString());
7373
}
7474

7575
public function toString(): string

src/Psl/Type/Internal/I16Type.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public function matches(mixed $value): bool
3939
*/
4040
public function coerce(mixed $value): int
4141
{
42-
$integer = Type\int()
43-
->withTrace($this->getTrace()->withFrame($this->toString()))
44-
->coerce($value);
42+
$integer = Type\int()->coerce($value);
4543

4644
if ($integer >= Math\INT16_MIN && $integer <= MATH\INT16_MAX) {
4745
return $integer;
4846
}
4947

50-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
48+
throw CoercionException::withValue($value, $this->toString());
5149
}
5250

5351
/**
@@ -67,7 +65,7 @@ public function assert(mixed $value): int
6765
return $value;
6866
}
6967

70-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
68+
throw AssertException::withValue($value, $this->toString());
7169
}
7270

7371
public function toString(): string

src/Psl/Type/Internal/I32Type.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ public function matches(mixed $value): bool
4040
*/
4141
public function coerce(mixed $value): int
4242
{
43-
$integer = Type\int()
44-
->withTrace($this->getTrace()->withFrame($this->toString()))
45-
->coerce($value);
43+
$integer = Type\int()->coerce($value);
4644

4745
if ($integer >= Math\INT32_MIN && $integer <= MATH\INT32_MAX) {
4846
return $integer;
4947
}
5048

51-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
49+
throw CoercionException::withValue($value, $this->toString());
5250
}
5351

5452
/**
@@ -68,7 +66,7 @@ public function assert(mixed $value): int
6866
return $value;
6967
}
7068

71-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
69+
throw AssertException::withValue($value, $this->toString());
7270
}
7371

7472
public function toString(): string

src/Psl/Type/Internal/I64Type.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ public function matches(mixed $value): bool
3838
*/
3939
public function coerce(mixed $value): int
4040
{
41-
return Type\int()
42-
->withTrace($this->getTrace()->withFrame($this->toString()))
43-
->coerce($value);
41+
return Type\int()->coerce($value);
4442
}
4543

4644
/**
@@ -60,7 +58,7 @@ public function assert(mixed $value): int
6058
return $value;
6159
}
6260

63-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
61+
throw AssertException::withValue($value, $this->toString());
6462
}
6563

6664
public function toString(): string

src/Psl/Type/Internal/I8Type.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ public function matches(mixed $value): bool
3939
*/
4040
public function coerce(mixed $value): int
4141
{
42-
$integer = Type\int()
43-
->withTrace($this->getTrace()->withFrame($this->toString()))
44-
->coerce($value);
42+
$integer = Type\int()->coerce($value);
4543

4644
if ($integer >= Math\INT8_MIN && $integer <= Math\INT8_MAX) {
4745
return $integer;
4846
}
4947

50-
throw CoercionException::withValue($value, $this->toString(), $this->getTrace());
48+
throw CoercionException::withValue($value, $this->toString());
5149
}
5250

5351
/**
@@ -67,7 +65,7 @@ public function assert(mixed $value): int
6765
return $value;
6866
}
6967

70-
throw AssertException::withValue($value, $this->toString(), $this->getTrace());
68+
throw AssertException::withValue($value, $this->toString());
7169
}
7270

7371
public function toString(): string

0 commit comments

Comments
 (0)