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

Bug in code generation #287

Open
2 tasks
MeAmAnUsername opened this issue Apr 11, 2022 · 0 comments
Open
2 tasks

Bug in code generation #287

MeAmAnUsername opened this issue Apr 11, 2022 · 0 comments
Labels
Component: code generation Something that concerns the generated code Priority: medium Status: specified Enhancement that is ready to implement Type: bug Something isn't working

Comments

@MeAmAnUsername
Copy link
Owner

Summary
A bug in code generation, possibly due to the if-else with nested generics

Todo

  • Make a test
  • Fix bug

Description
Example code:

data Fruit = foreign java Fruit {}
data Orange <: Fruit = foreign java Orange {}
data Banana <: Fruit = foreign java Banana {}

data Box[T] = foreign java Box {
  func get() -> T
}
func Box[T]() -> Box[T] = foreign java constructor Box

func mergeTypeArg() -> unit = {
  val box1: Box[Orange] = Box[Orange]();
  val box2: Box[Banana] = Box[Banana]();
  val box: Box[_ <: Fruit] = if (true) box1 else box2;
  unit
}

Given: run code generation (Spoofax > Generate > Java AST) on the example code
Expected: code generation finishes successfully.
Actual: code generation fails with an error:

13:38 | INFO  | stderr                         - start p2j-ast-def: "mergeTypeArg"{TermIndex("src/main/test.pie",125)}
13:38 | ERROR | o.m.s.e.t.TransformJob         - Transformation failed for eclipse:///test_ground/src/main/test.pie
org.metaborg.core.transform.TransformException: Invoking Stratego strategy generate-java-file-ast failed at term:
	Scope(".", "s_common_instance_1644-196")
Stratego trace:
	generate_java_file_ast_0_0
	with_1_1
	p2j_ast_0_0
	with_1_1
	dr_scope_1_1
	dr_scope_1_1
	dr_scope_1_1
	filter_1_0
	with_1_1
	dr_scope_1_1
	dr_scope_1_1
	p2j_ast_pie_func_impl_body_0_0
	with_1_1
	map_1_0
	try_p2j_ast_exp_0_0
	pie_try_debug_1_1
	s11
	with_1_1
	try_p2j_ast_exp_0_0
	pie_try_debug_1_1
	s11
	with_1_1
	p2j_ast_type_sig_0_0
	with_1_1
	pie_get_context_0_1
	with_1_1 <==
Internal error: 'with' clause failed unexpectedly in 'pie-get-context'
	at org.metaborg.spoofax.core.transform.StrategoTransformer.transform(StrategoTransformer.java:163)
	at org.metaborg.spoofax.core.transform.StrategoTransformer.transform(StrategoTransformer.java:86)
	at org.metaborg.spoofax.core.transform.StrategoTransformer.transform(StrategoTransformer.java:1)
	at org.metaborg.core.transform.TransformService.transform(TransformService.java:88)
	at org.metaborg.spoofax.eclipse.transform.TransformJob.transform(TransformJob.java:145)
	at org.metaborg.spoofax.eclipse.transform.TransformJob.transformAll(TransformJob.java:120)
	at org.metaborg.spoofax.eclipse.transform.TransformJob.run(TransformJob.java:80)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.spoofax.interpreter.core.InterpreterErrorExit: Internal error: 'with' clause failed unexpectedly in 'pie-get-context'
	at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:194)
	at org.strategoxt.lang.InteropSDefT.evaluate(InteropSDefT.java:183)
	at org.strategoxt.lang.InteropSDefT$StrategyBody.evaluate(InteropSDefT.java:245)
	at org.strategoxt.lang.InteropSDefT$StrategyBody.eval(InteropSDefT.java:238)
	at org.spoofax.interpreter.stratego.Strategy.evaluate(Strategy.java:86)
	at org.spoofax.interpreter.core.Interpreter.evaluate(Interpreter.java:105)
	at org.spoofax.interpreter.core.Interpreter.invoke(Interpreter.java:80)
	at org.strategoxt.HybridInterpreter.invoke(HybridInterpreter.java:458)
	at org.metaborg.spoofax.core.stratego.StrategoCommon.invoke(StrategoCommon.java:148)
	at org.metaborg.spoofax.core.transform.StrategoTransformer.transform(StrategoTransformer.java:161)
	... 7 common frames omitted
@MeAmAnUsername MeAmAnUsername added Type: bug Something isn't working Status: specified Enhancement that is ready to implement Component: code generation Something that concerns the generated code Priority: medium labels Apr 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: code generation Something that concerns the generated code Priority: medium Status: specified Enhancement that is ready to implement Type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant