diff --git a/src/repl/eval.zig b/src/repl/eval.zig index 76aa445ec2..d80a1aee43 100644 --- a/src/repl/eval.zig +++ b/src/repl/eval.zig @@ -239,12 +239,15 @@ pub const Repl = struct { return try std.fmt.allocPrint(self.allocator, "assigned `{s}`", .{info.var_name}); }, .type_annotation => |info| { - // Store the type annotation for future use + // For type annotations: + // 1. Store them as definitions for future use try self.addOrReplaceDefinition(info.source, info.var_name); - // Type annotations alone cannot be evaluated - they create e_anno_only which crashes when used - // Return a message indicating the annotation was stored - return try std.fmt.allocPrint(self.allocator, "Crash: runtime error", .{}); + // 2. Evaluate the full source (including all definitions + this annotation) + // This will create an e_anno_only which will crash when evaluated + const full_source = try self.buildFullSource(input); + defer self.allocator.free(full_source); + return try self.evaluateSource(full_source); }, .import => { // Imports are not supported in this implementation diff --git a/src/repl/repl_test.zig b/src/repl/repl_test.zig index 4aab7548d3..1157d70b54 100644 --- a/src/repl/repl_test.zig +++ b/src/repl/repl_test.zig @@ -402,10 +402,10 @@ test "Repl - standalone annotation should crash, then call should fail - REGRESS const result2 = try repl.step("foo(\"test\")"); defer std.testing.allocator.free(result2); - // Should return a canonicalization error since foo only has a type annotation, no definition - if (std.mem.indexOf(u8, result2, "Canonicalize expr error") == null) { - std.debug.print("\nexpected Canonicalize expr error, got: {s}\n", .{result2}); + // Should return "Evaluation error: error.TypeMismatch" + if (std.mem.indexOf(u8, result2, "TypeMismatch") == null) { + std.debug.print("\nexpected TypeMismatch, got: {s}\n", .{result2}); return error.TestUnexpectedResult; } - try testing.expect(std.mem.indexOf(u8, result2, "expression returned null for apply") != null); + try testing.expect(std.mem.indexOf(u8, result2, "Evaluation error") != null); } diff --git a/test/snapshots/repl/anno_only_crash.md b/test/snapshots/repl/anno_only_crash.md index a3f49c8cbc..efdda51bcc 100644 --- a/test/snapshots/repl/anno_only_crash.md +++ b/test/snapshots/repl/anno_only_crash.md @@ -11,6 +11,6 @@ type=repl # OUTPUT Crash: runtime error --- -Canonicalize expr error: expression returned null for apply +Evaluation error: error.TypeMismatch # PROBLEMS NIL