Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 2, 2024
1 parent ae9fc62 commit 91c95b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
28 changes: 19 additions & 9 deletions crates/rue-typing/src/substitute_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,31 @@ pub(crate) fn substitute_type(
}
}

match types.get(type_id) {
Type::Unknown
| Type::Generic
| Type::Never
| Type::Any
| Type::Bytes
| Type::Bytes32
| Type::PublicKey
| Type::Int
| Type::Nil
| Type::True
| Type::False
| Type::Value(..) => return type_id,
_ => {}
}

let placeholder = types.alloc(Type::Unknown);
substitutions
.last_mut()
.unwrap()
.insert(type_id, placeholder);

let result = match types.get(type_id) {
Type::Ref(..) => unreachable!(),
Type::Unknown
Type::Ref(..)
| Type::Unknown
| Type::Generic
| Type::Never
| Type::Any
Expand All @@ -32,7 +48,7 @@ pub(crate) fn substitute_type(
| Type::Nil
| Type::True
| Type::False
| Type::Value(..) => type_id,
| Type::Value(..) => unreachable!(),
Type::Pair(first, rest) => {
let (first, rest) = (*first, *rest);

Expand Down Expand Up @@ -67,7 +83,6 @@ pub(crate) fn substitute_type(
}
Type::Alias(alias) => {
let alias = alias.clone();

let new_type_id = substitute_type(types, alias.type_id, substitutions);

if new_type_id == alias.type_id {
Expand All @@ -82,7 +97,6 @@ pub(crate) fn substitute_type(
}
Type::Struct(ty) => {
let ty = ty.clone();

let new_type_id = substitute_type(types, ty.type_id, substitutions);

if new_type_id == ty.type_id {
Expand All @@ -99,7 +113,6 @@ pub(crate) fn substitute_type(
}
Type::Variant(ty) => {
let ty = ty.clone();

let new_type_id = substitute_type(types, ty.type_id, substitutions);

if new_type_id == ty.type_id {
Expand All @@ -118,7 +131,6 @@ pub(crate) fn substitute_type(
}
Type::Enum(ty) => {
let ty = ty.clone();

let new_type_id = substitute_type(types, ty.type_id, substitutions);

if new_type_id == ty.type_id {
Expand All @@ -134,9 +146,7 @@ pub(crate) fn substitute_type(
}
Type::Callable(callable) => {
let callable = callable.clone();

let new_return_type = substitute_type(types, callable.return_type, substitutions);

let new_parameters = substitute_type(types, callable.parameters, substitutions);

if new_return_type == callable.return_type && new_parameters == callable.parameters {
Expand Down
9 changes: 5 additions & 4 deletions tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@ output = "()"
hash = "146182f765c52c144e4fa6d44fd3073bb3cbed6fac2bf1ca15393fc244c7d2b8"

[cat]
bytes = 2107
cost = 359978
bytes = 2323
cost = 0
input = "(0x00f43ce9fcc63d5019e209c103e6b0aaf56bbe7fc7fafae5af7f5ee6887a8719 0xd622c62a7292ffee5cf2537a90360ca0b7337b76d7014ec042930c0a87592213 (q (g1_negate () -113 (a (q 2 (i 47 (q 8) (q 2 (i (= 45 2) () (q 8)) 1)) 1) (c (q . 0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861) 1)) ()) (g1_negate 0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001 1 (0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001))) () () 0x615236766bed52d7abaa41d270407f3ec852981852334b213bd8515924459a5d (0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861 0x1ecb863db5d2ae6c71e9a8b0741acb3e034e8164b8ca0e564d5fad8b9dc875d5 1) (0x895eb35a355941ba7f6a8679a73bb9b8b62cae2b04ef5351eda42583c0f2d861 0x130deb20b44082a68293974f8cab9c51e21f9a9f3005000168eb77e49e0fc378 1) () ())"
output = "((70 0x615236766bed52d7abaa41d270407f3ec852981852334b213bd8515924459a5d) (60 0xcb7f53b5de05b4afe58ab663b952aa785fd9ad911564709bd8eacbf4c58ba1e589) (61 0x389f1ea7b9fab7a9294104eb3a181d662f2dbe9c43fbe52802ba9b7eef357e77) (g1_negate 0xc9644528436f44cd9b33282684b4964f55d5551cb3a970ab9cf8f536e0d72ad1 1 (0xb8705f94744e7fc30300ac9b12d306b283f5a702937ee99beabf665be6023001)))"
hash = "00f43ce9fcc63d5019e209c103e6b0aaf56bbe7fc7fafae5af7f5ee6887a8719"
output = "()"
hash = "5db0d2b8b2ea766c75afdfee8127d704f41e849a781fda6655e305199d4c5e23"
error = "()"

[external_function]
bytes = 7
Expand Down

0 comments on commit 91c95b4

Please sign in to comment.