Skip to content

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

Merged
jdconrad merged 4 commits intoelastic:masterfrom
jdconrad:quackquack
Oct 4, 2021
Merged

Add dynamic (duck) type resolution to Painless static types#78575
jdconrad merged 4 commits intoelastic:masterfrom
jdconrad:quackquack

Conversation

@jdconrad
Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

@jdconrad jdconrad removed the request for review from stu-elastic October 4, 2021 14:56
}

TargetType targetType = userCallNode.isNullSafe() ? null : semanticScope.getDecoration(userCallNode, TargetType.class);
// TODO: remove ZonedDateTime exception when JodaCompatibleDateTime is removed
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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