Skip to content

GROOVY-9292: Compilation error when accessing a protected(via thisObject, owner and delegate)/package-private super class field from inside a closure#1048

Closed
daniellansun wants to merge 3 commits intoapache:masterfrom
daniellansun:GROOVY-9288-REWORK
Closed

GROOVY-9292: Compilation error when accessing a protected(via thisObject, owner and delegate)/package-private super class field from inside a closure#1048
daniellansun wants to merge 3 commits intoapache:masterfrom
daniellansun:GROOVY-9288-REWORK

Conversation

@daniellansun
Copy link
Copy Markdown
Contributor

@daniellansun daniellansun commented Oct 28, 2019

No description provided.

@eric-milles
Copy link
Copy Markdown
Member

Can you reframe the remaining problems as a new ticket? The original GROOVY-9288 issue should be fixed in my estimation.

Also, you have test cases disabled with a boolean switch. Can you use @ignore or @NotYetImplemented to disable them? And do you expect those test cases to work? It was unclear if they indicate a different problem or unsolved part of the current issue.

@daniellansun
Copy link
Copy Markdown
Contributor Author

Even if the fix for GROOVY-7996 was rolled back, protected field can not be accessed via thisObject, owner and delegate : #1046 (comment)
So the original description of GROOVY-9288 have to be refined too.

@daniellansun daniellansun changed the title REWORK GROOVY-9288: Compilation error when accessing a protected/publ… GROOVY-9292: Compilation error when accessing a protected(via thisObject, owner and delegate)/package-private super class field from inside a closure Oct 28, 2019
@eric-milles
Copy link
Copy Markdown
Member

eric-milles commented Oct 28, 2019

Here is another take on your change that checks protected and package-private access for the closure's enclosing type.

                if (field != null && !field.isPublic()
                        && objectExpression instanceof VariableExpression
                        && typeCheckingContext.getEnclosingClosure() != null
                        && (
                            (field.isProtected() && typeCheckingContext.getEnclosingClassNode().isDerivedFrom(current))
                             ||
                            (!field.isPrivate() && Objects.equals(typeCheckingContext.getEnclosingClassNode().getPackageName(), current.getPackageName()))
                           )
                ) {
                    switch (objectExpression.getText()) {
                    case "it":
                    case "owner":
                    case "delegate":
                    case "thisObject":
                        pexp.putNodeMetaData(DYNAMIC_RESOLUTION, Boolean.TRUE);
                    }
                }

I'm still not too keen on dynamic properties. But at least this should stop conversion of forbidden access to missing property. What does not match up is that explicit-this and implicit-this don't produce compiler errors, but instead result in missing property exceptions. I'm just not sure if we know enough to proceed on a change...

@daniellansun
Copy link
Copy Markdown
Contributor Author

@eric-milles Let's make it work, then work better, at last work perfectly ;-)

Replaced with #1050

@daniellansun
Copy link
Copy Markdown
Contributor Author

@eric-milles BTW, I will add your tweak in PR #1050 with your commit info reserved

@daniellansun
Copy link
Copy Markdown
Contributor Author

@eric-milles After your patch applied, the following tests fails, so I will keep the original PR as it is for now:

image

@daniellansun
Copy link
Copy Markdown
Contributor Author

@eric-milles parts of your patch is applied: ae0bc9f

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