Skip to content

Add support for anonymous classes#273

Open
drdzyk wants to merge 1 commit intomasterfrom
seismont/add-support-for-anonymous-classes
Open

Add support for anonymous classes#273
drdzyk wants to merge 1 commit intomasterfrom
seismont/add-support-for-anonymous-classes

Conversation

@drdzyk
Copy link
Contributor

@drdzyk drdzyk commented Jun 29, 2021

This PR add support for php's anonymous classes

@drdzyk drdzyk added the enhancement New feature or request label Jun 29, 2021

function test_one_ctor_arg() {
new class(77) {
function __construct($num) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add a @kphp_should_fail test like

  $int = 77;
  new class($int) {
    function __construct(string $num) { }
  }

(an error in types)
Let's see whether this error points to a correct location and stacktrace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, please check comment.

@drdzyk drdzyk force-pushed the seismont/add-support-for-anonymous-classes branch from f0850f6 to 3485984 Compare July 1, 2021 08:43
};
}

test_constructor_type_mismatch();
Copy link
Contributor Author

@drdzyk drdzyk Jul 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full log of compiler error:

Compilation error at stage: Calc actual calls, gen by type-inferer.cpp:53
  007_constructor_type_mismatch.php:6  in test_constructor_type_mismatch
    new class(42) {

pass int to argument $num of anon_class\ue076317298712440_0::__construct
but it's declared as @param string

  007_constructor_type_mismatch.php:6  in test_constructor_type_mismatch
    new class(42) {
    42 is int


Compilation terminated due to errors

@Tsygankov-Slava Tsygankov-Slava mentioned this pull request Aug 7, 2023
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants