Skip to content

Commit

Permalink
Changes Unifier to use enum and scruct callpaths.
Browse files Browse the repository at this point in the history
  • Loading branch information
esdrubal committed Jan 30, 2023
1 parent f7153cb commit 0caaf2e
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions sway-core/src/type_system/unify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ use sway_error::{
type_error::TypeError,
warning::{CompileWarning, Warning},
};
use sway_types::{integer_bits::IntegerBits, Ident, Span, Spanned};
use sway_types::{integer_bits::IntegerBits, Span, Spanned};

use crate::{engine_threading::*, language::ty, type_system::*};
use crate::{
engine_threading::*,
language::{ty, CallPath},
type_system::*,
};

/// Helper struct to aid in type unification.
pub(super) struct Unifier<'a> {
Expand Down Expand Up @@ -116,13 +120,7 @@ impl<'a> Unifier<'a> {
type_parameters: etps,
fields: efs,
},
) => self.unify_structs(
received,
expected,
span,
(rn.suffix, rpts, rfs),
(en.suffix, etps, efs),
),
) => self.unify_structs(received, expected, span, (rn, rpts, rfs), (en, etps, efs)),
// Let empty enums to coerce to any other type. This is useful for Never enum.
(
Enum {
Expand All @@ -141,13 +139,7 @@ impl<'a> Unifier<'a> {
type_parameters: etps,
variant_types: evs,
},
) => self.unify_enums(
received,
expected,
span,
(rn.suffix, rtps, rvs),
(en.suffix, etps, evs),
),
) => self.unify_enums(received, expected, span, (rn, rtps, rvs), (en, etps, evs)),

// For integers and numerics, we (potentially) unify the numeric
// with the integer.
Expand Down Expand Up @@ -347,8 +339,8 @@ impl<'a> Unifier<'a> {
received: TypeId,
expected: TypeId,
span: &Span,
r: (Ident, Vec<TypeParameter>, Vec<ty::TyStructField>),
e: (Ident, Vec<TypeParameter>, Vec<ty::TyStructField>),
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyStructField>),
) -> (Vec<CompileWarning>, Vec<TypeError>) {
let mut warnings = vec![];
let mut errors = vec![];
Expand Down Expand Up @@ -396,8 +388,8 @@ impl<'a> Unifier<'a> {
received: TypeId,
expected: TypeId,
span: &Span,
r: (Ident, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
e: (Ident, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
r: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
e: (CallPath, Vec<TypeParameter>, Vec<ty::TyEnumVariant>),
) -> (Vec<CompileWarning>, Vec<TypeError>) {
let mut warnings = vec![];
let mut errors = vec![];
Expand Down

0 comments on commit 0caaf2e

Please sign in to comment.