Skip to content

Conversation

iluuu1994
Copy link
Member

Fixes GH-17214

Small note: I thought we'd have to support as final private, which would not work with this approach. But then noticed that strangely the grammar only allows for a single modifier for the trait alias. Thus, we luckily don't need to handle the case where both final and the visibility can change.

@nielsdos
Copy link
Member

nielsdos commented Jan 6, 2025

Right, so now only this situation creates the warning (if it hadn't already warned earlier):

<?php

trait MyTrait {
    private function someMethod(): void {}
}

class Test {
    use MyTrait {
        someMethod as final anotherMethod;
    }
}

Note though that relaxing the warning might go against the copy+paste behaviour that traits try to mimick, as copy pasting with the editing visibility would generate a warning too. This was the point of introducing the warning. Anyway, I'm not really objecting.

@iluuu1994
Copy link
Member Author

Note though that relaxing the warning might go against the copy+paste behaviour that traits try to mimick

That's a fair pair point. I think this is slightly different in that it the method isn't just copy&pasted, but also modified. Since we don't allow removing modifiers, it seems relaxing this warning would enable a reasonable use-case that worked previously, when you cannot remove final on the trait itself.

@nielsdos
Copy link
Member

nielsdos commented Jan 7, 2025

I guess it's a matter of perspective, I don't object.

@iluuu1994 iluuu1994 closed this in a6a290d Jan 13, 2025
charmitro pushed a commit to wasix-org/php that referenced this pull request Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants