Skip to content

Commit 3c1976b

Browse files
committed
feat(#5264): make PhTerminated reject every interaction, not only delta
1 parent 8103879 commit 3c1976b

2 files changed

Lines changed: 70 additions & 6 deletions

File tree

eo-runtime/src/main/java/org/eolang/PhTerminated.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,63 @@
77
/**
88
* The ⊥ ("bottom") object of φ-calculus — a terminated computation.
99
*
10-
* <p>It carries no data and no attributes. Dataizing it aborts the
11-
* program with an {@link ExFailure}, which EO {@code try} cannot catch
12-
* (that object only intercepts {@link EOerror.ExError}), so reaching ⊥
13-
* terminates the program for good.</p>
10+
* <p>It has no data, no attributes, and no behaviour: every interaction
11+
* with it aborts the program through an {@link ExFailure}. Because EO
12+
* {@code try} only intercepts {@link EOerror.ExError}, this failure
13+
* cannot be caught, so touching ⊥ terminates the program for good.</p>
1414
*
1515
* @since 0.73.1
1616
*/
17-
public final class PhTerminated extends PhDefault {
17+
public final class PhTerminated implements Phi {
18+
19+
/**
20+
* The message of the failure raised by every interaction with ⊥.
21+
*/
22+
private static final String MESSAGE =
23+
"the ⊥ object is a terminated computation and cannot be used";
24+
25+
@Override
26+
public Phi copy() {
27+
throw new ExFailure(PhTerminated.MESSAGE);
28+
}
29+
30+
@Override
31+
public boolean hasRho() {
32+
throw new ExFailure(PhTerminated.MESSAGE);
33+
}
34+
35+
@Override
36+
public Phi take(final String name) {
37+
throw new ExFailure(PhTerminated.MESSAGE);
38+
}
39+
40+
@Override
41+
public void put(final int pos, final Phi object) {
42+
throw new ExFailure(PhTerminated.MESSAGE);
43+
}
44+
45+
@Override
46+
public void put(final String name, final Phi object) {
47+
throw new ExFailure(PhTerminated.MESSAGE);
48+
}
49+
50+
@Override
51+
public String locator() {
52+
throw new ExFailure(PhTerminated.MESSAGE);
53+
}
54+
55+
@Override
56+
public String forma() {
57+
throw new ExFailure(PhTerminated.MESSAGE);
58+
}
1859

1960
@Override
2061
public byte[] delta() {
21-
throw new ExFailure("the ⊥ object is a terminated computation and cannot be dataized");
62+
throw new ExFailure(PhTerminated.MESSAGE);
63+
}
64+
65+
@Override
66+
public String φTerm() {
67+
throw new ExFailure(PhTerminated.MESSAGE);
2268
}
2369
}

eo-runtime/src/test/java/org/eolang/PhTerminatedTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,22 @@ void failsWhenDataized() {
2121
"dataizing the bottom object must abort instead of returning data"
2222
);
2323
}
24+
25+
@Test
26+
void failsWhenDispatched() {
27+
Assertions.assertThrows(
28+
ExFailure.class,
29+
() -> new PhTerminated().take("any"),
30+
"dispatching an attribute on the bottom object must abort"
31+
);
32+
}
33+
34+
@Test
35+
void failsWhenCopied() {
36+
Assertions.assertThrows(
37+
ExFailure.class,
38+
() -> new PhTerminated().copy(),
39+
"copying the bottom object must abort"
40+
);
41+
}
2442
}

0 commit comments

Comments
 (0)