feat(pbs): implement typed arrays, optional binding and contract execution
This commit is contained in:
+9
-8
@@ -312,7 +312,7 @@ class PbsFrontendCompilerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void shouldRejectAmbiguousCallableIdentityInsteadOfGuessingByText() {
|
||||
void shouldResolveOverloadedCallableUsingItsTypedArgument() {
|
||||
final var source = """
|
||||
fn draw_pixel(x: int) -> int {
|
||||
return x;
|
||||
@@ -331,13 +331,14 @@ class PbsFrontendCompilerTest {
|
||||
final var compiler = new PbsFrontendCompiler();
|
||||
final var fileBackend = compiler.compileFile(new FileId(45), source, diagnostics);
|
||||
|
||||
final var loweringDiagnostic = diagnostics.stream()
|
||||
.filter(d -> d.getCode().equals(PbsSemanticsErrors.E_SEM_EXEC_LOWERING_UNRESOLVED_CALLEE.name()))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
assertEquals(DiagnosticPhase.STATIC_SEMANTICS, loweringDiagnostic.getPhase());
|
||||
assertTrue(loweringDiagnostic.getMessage().contains("ambiguous callable identity"));
|
||||
assertEquals(0, fileBackend.executableFunctions().size());
|
||||
assertFalse(diagnostics.hasErrors(), diagnostics.toString());
|
||||
var integerOverload = fileBackend.executableFunctions().stream()
|
||||
.filter(function -> function.callableName().equals("draw_pixel")).findFirst().orElseThrow();
|
||||
var main = fileBackend.executableFunctions().stream().filter(function -> function.callableName().equals("main")).findFirst().orElseThrow();
|
||||
var call = main.instructions().stream().filter(instruction -> instruction.kind() == IRBackendExecutableFunction.InstructionKind.CALL_FUNC)
|
||||
.findFirst().orElseThrow();
|
||||
assertEquals(integerOverload.callableId(), call.calleeCallableId());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+28
@@ -16,6 +16,34 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
final class PbsEditorialSupportServiceTest {
|
||||
private final PbsEditorialSupportService service = new PbsEditorialSupportService();
|
||||
|
||||
@Test
|
||||
void arrayAndOptionalBindingShareEditorialScope() {
|
||||
String source = """
|
||||
declare struct Enemy(pub hp: int) { fn health() -> int { return this.hp; } }
|
||||
fn main() {
|
||||
let enemies: array Enemy = new array(2);
|
||||
if let enemy = enemies[0] { let hp = enemy.health(); }
|
||||
enemies.clear(0);
|
||||
}
|
||||
""";
|
||||
var ast = parseOrdinary(source);
|
||||
int use = source.indexOf("enemy.health");
|
||||
assertFalse(service.definition(source, ast, ReadOnlyList.empty(), use).isEmpty());
|
||||
assertTrue(service.hover(source, ast, ReadOnlyList.empty(), use).isPresent());
|
||||
assertTrue(service.completion(source, ast, ReadOnlyList.empty(), use + "enemy.".length()).stream()
|
||||
.anyMatch(item -> item.label().equals("health")));
|
||||
var rename = service.rename(source, ast, ReadOnlyList.empty(), use, "selected");
|
||||
assertTrue(rename.allowed(), rename.refusal());
|
||||
assertEquals(2, rename.sites().size(), rename.sites().toString());
|
||||
var declarationRename = service.rename(source, ast, ReadOnlyList.empty(), source.indexOf("enemy ="), "selected");
|
||||
assertTrue(declarationRename.allowed(), declarationRename.refusal());
|
||||
assertEquals(2, declarationRename.sites().size());
|
||||
int clear = source.indexOf("enemies.clear") + "enemies.".length();
|
||||
assertTrue(service.completion(source, ast, ReadOnlyList.empty(), clear).stream()
|
||||
.anyMatch(item -> item.label().equals("length")));
|
||||
assertTrue(service.hover(source, ast, ReadOnlyList.empty(), clear).isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void receiverMatrixHandlesNestedCallsVariablesParenthesesAndRecovery() {
|
||||
final String declarations = """
|
||||
|
||||
Reference in New Issue
Block a user