Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[go1.21] Adding new / replace optional override directives#1414

Merged
grantnelson-wf merged 2 commits intogopherjs:go1.21from
Workiva:newOverrideDirectives
Feb 24, 2026
Merged

[go1.21] Adding new / replace optional override directives#1414
grantnelson-wf merged 2 commits intogopherjs:go1.21from
Workiva:newOverrideDirectives

Conversation

@grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Feb 20, 2026

This is part of the proposal issue #1330, "Proposal: More strict native override checking". This adds the gopherjs:new and gopherjs:replace optional directives. Additionally, I added the new missing method to bytealg and added these directives as a test. Since this is being added to the go1.21 integration branch, CI will continue to fail. This code includes the update to master so that PR should be merged before this one.

Between Go1.20 and Go1.21, the Go developers refactored reflect and internal/reflectlite by moving a lot of code over to internal/abi. Since so much code was in internal packages; the developers weren't required to keep exported code consistent other than in reflect. Since there was so much code being moved, it was difficult for me to determine what was new code to go1.20, code being replaced in go1.20, then which code is new in go1.21 and replaced in go1.21. Any code that was a replacement for go1.20 of code that got moved, removed, or renamed in go1.21 would suddenly become new code we are adding.

I didn't want to leave around a bunch of code that hopefully had no effect (and hopefully just removed with dead code elimination), so I implemented this part of the proposal to help me track how our overrides are being applied.

These overrides are compiler enforced "developer intensions" just like the override modifier in C# and other modifiers in many languages. The code could quietly decide if we are overriding code or adding new code, or with these directives we can ensure that overrides work as the developer intended at compile time.

The full proposal is probably overkill at this time because of how strict is. These directives are not required so we don't have to add them to all of the overrides in one pass. The only change that this will effect is any of the existing override directives (i.e. purge, keep-original, and override-signature) will start acting like gopherjs:replace and raise an error if the code that they are attached to doesn't exist.

Instead of adding this code, then removing it once I have reflect, reflectlite, and abi working, I felt this would be a good time to add these directives. We already have to go through the native overrides while upgrading to go1.21 so any of the existing override directives can be updated as needed and we can add in these new directives if we feel it will help us when we upgrade to go1.22.

However, if you think that this is not a good idea to add; I have no problem skipping it and removing it from the reflect, reflectlite, and abi updates.

Related to #1415

@grantnelson-wf grantnelson-wf self-assigned this Feb 20, 2026
@grantnelson-wf grantnelson-wf marked this pull request as ready for review February 20, 2026 18:01
@grantnelson-wf grantnelson-wf changed the title Adding new / replace optional override directives [go1.21] Adding new / replace optional override directives Feb 20, 2026
Copy link
Member

@nevkontakte nevkontakte left a comment

Choose a reason for hiding this comment

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

I like this idea, it can help us get to a better-defined overrides incrementally. Thanks!

@grantnelson-wf grantnelson-wf merged commit c4be02f into gopherjs:go1.21 Feb 24, 2026
1 of 10 checks passed
@grantnelson-wf grantnelson-wf deleted the newOverrideDirectives branch February 24, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants