-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Zend: Resolve self and parent types at compile time #17755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Girgias
merged 4 commits into
php:master
from
Girgias:resolve-relative-types-compile-time
Feb 11, 2025
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...section_types/relative_types/relative_parent_type_is_allow_when_compile_time_resolve.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
parent type can take part in an intersection type is resolvable at compile time | ||
--FILE-- | ||
<?php | ||
|
||
class A {} | ||
|
||
class B extends A { | ||
public function foo(): parent&Iterator {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECT-- | ||
DONE |
7 changes: 3 additions & 4 deletions
7
...es/invalid_types/invalid_parent_type.phpt → ...ot_allow_if_not_compile_time_resolve.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
--TEST-- | ||
parent type cannot take part in an intersection type | ||
parent type cannot take part in an intersection type if not resolvable at compile time | ||
--FILE-- | ||
<?php | ||
|
||
class A {} | ||
|
||
class B extends A { | ||
trait T { | ||
public function foo(): parent&Iterator {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Type parent cannot be part of an intersection type in %s on line %d |
13 changes: 13 additions & 0 deletions
13
...ersection_types/relative_types/relative_self_type_is_allow_when_compile_time_resolve.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
self type can take part in an intersection type is resolvable at compile time | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
public function foo(): self&Iterator {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECT-- | ||
DONE |
5 changes: 3 additions & 2 deletions
5
...ypes/invalid_types/invalid_self_type.phpt → ...ot_allow_if_not_compile_time_resolve.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
--TEST-- | ||
self type cannot take part in an intersection type | ||
self type cannot take part in an intersection type if not resolvable at compile time | ||
--FILE-- | ||
<?php | ||
|
||
class A { | ||
trait T { | ||
public function foo(): self&Iterator {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Type self cannot be part of an intersection type in %s on line %d |
15 changes: 15 additions & 0 deletions
15
...s/type_declarations/union_types/redundant_types/duplicate_relative_class_parent_type.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--TEST-- | ||
Duplicate parent type | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data) {} | ||
} | ||
class Bar extends Foo { | ||
public function method(array $data): parent|parent {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
12 changes: 12 additions & 0 deletions
12
...sts/type_declarations/union_types/redundant_types/duplicate_relative_class_self_type.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Duplicate self type | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data): self|self {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
12 changes: 12 additions & 0 deletions
12
...s/type_declarations/union_types/redundant_types/duplicate_relative_class_static_type.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--TEST-- | ||
Duplicate static type | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data): static|static {} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Duplicate type static is redundant in %s on line %d |
13 changes: 13 additions & 0 deletions
13
...ations/union_types/redundant_types/duplicate_resolved_relative_class_type_variation1.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Relative class type self resolving to an existing entry (after variation) | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data): Foo|self {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
13 changes: 13 additions & 0 deletions
13
...ations/union_types/redundant_types/duplicate_resolved_relative_class_type_variation2.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--TEST-- | ||
Relative class type self resolving to an existing entry (before variation) | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data): self|Foo {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
16 changes: 16 additions & 0 deletions
16
...ations/union_types/redundant_types/duplicate_resolved_relative_class_type_variation3.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Relative class type parent resolving to an existing entry (after variation) | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data) {} | ||
} | ||
class Bar extends Foo { | ||
public function method(array $data): Foo|parent {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
16 changes: 16 additions & 0 deletions
16
...ations/union_types/redundant_types/duplicate_resolved_relative_class_type_variation4.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--TEST-- | ||
Relative class type parent resolving to an existing entry (before variation) | ||
--FILE-- | ||
<?php | ||
|
||
class Foo { | ||
public function method(array $data) {} | ||
} | ||
class Bar extends Foo { | ||
public function method(array $data): parent|Foo {} | ||
} | ||
|
||
?> | ||
DONE | ||
--EXPECTF-- | ||
Fatal error: Duplicate type Foo is redundant in %s on line %d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.