Skip to content

Commit

Permalink
[WIP] Demonstrate implementation of unapply
Browse files Browse the repository at this point in the history
  • Loading branch information
Akirathan committed Dec 24, 2024
1 parent e7dc725 commit 0a1f5a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.enso.runtime.parser.dsl.IRChild;
import org.enso.runtime.parser.dsl.IRField;
import scala.Option;
import scala.Tuple3;

/** Call-site arguments in Enso. */
public interface JCallArgument extends IR {
Expand Down Expand Up @@ -38,5 +39,9 @@ public JSpecified(
@IRField boolean isSynthetic, @IRChild Option<Name> name, @IRChild Expression value) {
super(isSynthetic, name, value);
}

public static Option<Tuple3<Boolean, Option<Name>, Expression>> unapply(JSpecified self) {
return Option.apply(new Tuple3<>(self.isSynthetic(), self.name(), self.value()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ class GeneratedIRTest extends AnyFlatSpec with Matchers {
val dupl = callArg.duplicate(false, false, false, false)
dupl.value() shouldEqual lit
}

"JSpecified" should "can implement unapply" in {
val lit = Literal.Text("foo", null, new MetadataStorage())
val callArg = new JSpecified(true, None, lit)
callArg match {
case JSpecified(isSynthetic, _, _) =>
isSynthetic shouldEqual true
}
}
}

0 comments on commit 0a1f5a8

Please sign in to comment.