checkpoint
This commit is contained in:
parent
e5485995ed
commit
61e95be622
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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) <! list(integer)" do
|
||||
int_list = {:list_of, :integer}
|
||||
any_list = {:list_of, :any}
|
||||
assert_subtype(:integer, :any)
|
||||
refute_subtype({:cons, {:literal, :a}, {:literal, []}}, int_list)
|
||||
refute_subtype(any_list, int_list)
|
||||
end
|
||||
|
||||
@doc "Tests that manually-defined recursive types (like a binary tree) can be compiled and checked correctly."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user