From 61e95be62264a05e0151a3f8da5da8ee143e4b05 Mon Sep 17 00:00:00 2001 From: Kacper Marzecki Date: Sat, 12 Jul 2025 12:23:14 +0200 Subject: [PATCH] checkpoint --- lib/debug.ex | 6 +++--- lib/til.ex | 5 +++++ test/til_test.exs | 18 ++++++++---------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/debug.ex b/lib/debug.ex index 8776ca8..4845418 100644 --- a/lib/debug.ex +++ b/lib/debug.ex @@ -606,9 +606,9 @@ defmodule Tdd.Debug do # --- TDD Graph Printing (Kept as it was, assuming it's for a different purpose) --- @doc "Prints a formatted representation of a TDD graph structure." - def print_tdd_graph(id, store_module \\ Tdd.Store) do - IO.puts("--- TDD Graph (ID: #{id}) ---") - do_print_tdd_node(id, 0, MapSet.new(), store_module) + def print_tdd_graph(id, label \\ "") do + IO.puts("---#{label} TDD Graph (ID: #{id}) ---") + do_print_tdd_node(id, 0, MapSet.new(), Tdd.Store) IO.puts("------------------------") end diff --git a/lib/til.ex b/lib/til.ex index 730336f..74403ba 100644 --- a/lib/til.ex +++ b/lib/til.ex @@ -1357,6 +1357,7 @@ defmodule Tdd.Algo do Store.put_op_cache(cache_key, result_id) result_id end + |> simplify() end # This function is correct and does not need to be changed. @@ -2120,9 +2121,13 @@ defmodule Tdd.Compiler do Store.init() id1 = spec_to_id(spec1) + Debug.print_tdd_graph(id1, "IS_SUBTYPE id1") id2 = spec_to_id(spec2) + Debug.print_tdd_graph(id2, "IS_SUBTYPE id2") neg_id2 = Algo.negate(id2) + Debug.print_tdd_graph(neg_id2, "IS_SUBTYPE neg_id2") intersect_id = Algo.apply(:intersect, &op_intersect_terminals/2, id1, neg_id2) + Debug.print_tdd_graph(intersect_id, "IS_SUBTYPE intersect") # The crash was because `intersect_id` was not an integer, which should not # happen if `apply` works correctly on valid IDs. By fixing the state diff --git a/test/til_test.exs b/test/til_test.exs index 3865245..d125289 100644 --- a/test/til_test.exs +++ b/test/til_test.exs @@ -380,22 +380,20 @@ defmodule TddSystemTest do # These tests target the most complex features: recursive and polymorphic types. # --- describe "Tdd.Compiler: Advanced Features (μ, Λ, Apply)" do - @doc """ - It checks for covariance in generic types: a list of integers is a subtype of a list of anything, - but the reverse is not true. This requires the system to correctly handle coinductive reasoning - on the recursive TDD nodes. - """ - test "the previously crashing recursive subtype test now passes" do + test "list subtyping: list(int) <: list(any)" do int_list = {:list_of, :integer} any_list = {:list_of, :any} assert_subtype(:integer, :any) - # The key test that was failing due to the bug assert_subtype(int_list, any_list) - refute_subtype(any_list, int_list) - - # Also test instances against the recursive type assert_subtype({:cons, {:literal, 1}, {:literal, []}}, int_list) + end + + test "list subtyping: list(any)