Skip to content
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

Add dynamic (duck) type resolution to Painless static types #78575

Merged
merged 4 commits into from
Oct 4, 2021

Conversation

jdconrad
Copy link
Contributor

@jdconrad jdconrad commented Oct 1, 2021

This change adds dynamic (duck) type resolution to Painless static types using an annotation ( at dynamic_type ) to control which static types are allowed to be dynamically invoked. This annotation does not chain so any sub classes that also require dynamic type resolution must be annotated as well.

Example:

Java:
class A {
}

class B {
   String duck() { returns "duck"; }
}

allow list:
class A @dynamic_type {
}

class B {
  ()
  String duck()
}

Painless:
A a = new B();
a.duck();

Normally, this would fail as a is statically typed, so the method duck would not be found. With dynamic type resolution, this will succeed by seeing that we have a possible duck method on a sub class and binding the method at runtime instead.

@jdconrad jdconrad added >enhancement :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache v8.0.0 v7.16.0 labels Oct 1, 2021
@jdconrad jdconrad requested a review from stu-elastic October 1, 2021 21:09
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Oct 1, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@jdconrad jdconrad removed the request for review from stu-elastic October 4, 2021 14:56
@@ -2904,34 +2943,12 @@ public void visitCall(ECall userCallNode, SemanticScope semanticScope) {
}

TargetType targetType = userCallNode.isNullSafe() ? null : semanticScope.getDecoration(userCallNode, TargetType.class);
// TODO: remove ZonedDateTime exception when JodaCompatibleDateTime is removed
Copy link
Contributor

Choose a reason for hiding this comment

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

JodaCompatibleDateTime

was this missed in #78417?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! I searched for the class usages as opposed to just the name.

Copy link
Contributor

@stu-elastic stu-elastic left a comment

Choose a reason for hiding this comment

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

very clean

@jdconrad jdconrad merged commit f6fbeb8 into elastic:master Oct 4, 2021
@jdconrad
Copy link
Contributor Author

jdconrad commented Oct 4, 2021

@stu-elastic Thanks for the review!

jdconrad added a commit that referenced this pull request Oct 4, 2021
This change adds dynamic (duck) type resolution to Painless static types using an annotation ( at
dynamic_type ) to control which static types are allowed to be dynamically invoked. This annotation
does not chain so any sub classes that also require dynamic type resolution must be annotated as
well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >enhancement Team:Core/Infra Meta label for core/infra team v7.16.0 v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants