implements PR-08.1

This commit is contained in:
2026-03-24 13:42:32 +00:00
parent e11cfee9a4
commit 40188b67ab
2 changed files with 250 additions and 10 deletions
@@ -867,6 +867,70 @@ class PBSFrontendPhaseServiceTest {
+ executableNames);
}
@Test
void shouldResolveIntrinsicChainsWithMethodNameCollisionsByOwnerIdentity() throws IOException {
final var projectRoot = tempDir.resolve("project-intrinsic-owner-collision");
final var sourceRoot = projectRoot.resolve("src");
Files.createDirectories(sourceRoot);
final var sourceFile = sourceRoot.resolve("main.pbs");
final var modBarrel = sourceRoot.resolve("mod.barrel");
Files.writeString(sourceFile, """
import { Input } from @sdk:input;
fn frame() -> void
{
Input.pad().x().pressed();
Input.touch().x();
}
""");
Files.writeString(modBarrel, "pub fn frame() -> void;");
final var projectTable = new ProjectTable();
final var fileTable = new FileTable(1);
final var projectId = projectTable.register(ProjectDescriptor.builder()
.rootPath(projectRoot)
.name("main")
.version("1.0.0")
.sourceRoots(ReadOnlyList.wrap(List.of(sourceRoot)))
.build());
registerFile(projectId, projectRoot, sourceFile, fileTable);
registerFile(projectId, projectRoot, modBarrel, fileTable);
final var ctx = new FrontendPhaseContext(
projectTable,
fileTable,
new BuildStack(ReadOnlyList.wrap(List.of(projectId))),
1);
final var diagnostics = DiagnosticSink.empty();
final var irBackend = new PBSFrontendPhaseService().compile(
ctx,
diagnostics,
LogAggregator.empty(),
BuildingIssueSink.empty());
assertTrue(diagnostics.stream().noneMatch(d ->
d.getCode().equals(PbsSemanticsErrors.E_SEM_EXEC_LOWERING_UNRESOLVED_CALLEE.name())),
diagnostics.stream().map(d -> d.getCode() + ":" + d.getMessage()).toList().toString());
final var frameExecutable = irBackend.getExecutableFunctions().stream()
.filter(function -> "frame".equals(function.callableName()))
.findFirst()
.orElseThrow();
final var intrinsicCalls = frameExecutable.instructions().stream()
.filter(instruction ->
instruction.kind() == p.studio.compiler.models.IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC
&& instruction.intrinsicCall() != null)
.map(instruction -> instruction.intrinsicCall().canonicalName())
.toList();
assertTrue(intrinsicCalls.contains("input.pad"));
assertTrue(intrinsicCalls.contains("input.pad.x"));
assertTrue(intrinsicCalls.contains("input.button.pressed"));
assertTrue(intrinsicCalls.contains("input.touch"));
assertTrue(intrinsicCalls.contains("input.touch.x"));
}
private void registerFile(
final ProjectId projectId,
final Path projectRoot,