-
Notifications
You must be signed in to change notification settings - Fork 2
feat: lambda表达式支持 (invokedynamic) #3
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
Changes from all commits
9fce905
b231a96
8deff90
6da74f0
be448d1
70c87ae
0f1e559
d24fa40
19cc029
af4505b
beff805
7def4ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,6 +249,7 @@ pub enum JavaSyntaxKind { | |
| PatternExpr, | ||
|
|
||
| LambdaExpr, | ||
| LambdaParam, | ||
| MethodRefExpr, | ||
|
|
||
| Annotation, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,6 +184,31 @@ impl ClassCatalog { | |
| } | ||
| } | ||
|
|
||
| pub fn is_interface(&self, internal_name: &str) -> bool { | ||
| self.interfaces.contains(internal_name) | ||
| } | ||
|
|
||
| pub fn functional_interface_method(&self, internal_name: &str) -> Option<MethodRef> { | ||
| if !self.interfaces.contains(internal_name) { | ||
| return None; | ||
| } | ||
|
|
||
| let mut sam: Option<MethodRef> = None; | ||
| for ((owner, _), methods) in &self.methods { | ||
| if owner == internal_name { | ||
| for m in methods { | ||
| if m.is_interface { | ||
| if sam.is_some() { | ||
| return None; | ||
| } | ||
| sam = Some(m.clone()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| sam | ||
| } | ||
|
Comment on lines
+191
to
+210
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: functional_interface_method doesn't distinguish abstract from default/static methods The new Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| pub fn resolve_static_field(&self, owner: &str, name: &str) -> Option<FieldRef> { | ||
| self.lookup_order(owner).into_iter().find_map(|owner| { | ||
| self.fields | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Lambda synthetic method uses expression type for return opcode instead of declared SAM return type
In
scan_and_gen_lambdas, forLambdaBody::Expr, the return opcode is computed frombody_ty(the expression's inferred type) rather thanctx.return_ty/sam_info.return_ty(the declared return type of the synthetic method). When the expression type differs from the SAM return type, this produces invalid bytecode. For example, aConsumer<String>lambda whose body islist.add(x)(returns boolean) would emitIRETURNin a method declared as(Ljava/lang/Object;)V, causing a JVMVerifyError. Similarly, aSupplier<Integer>lambda like() -> 42would emitIRETURNinstead ofARETURN, since the expression type isintbut the erased impl descriptor returnsLjava/lang/Object;. No coercion betweenbody_tyand the method's return type is applied either.Prompt for agents
Was this helpful? React with 👍 or 👎 to provide feedback.