diff --git a/ast/src/constrain.rs b/ast/src/constrain.rs index 561da5c644..1b1eded9c9 100644 --- a/ast/src/constrain.rs +++ b/ast/src/constrain.rs @@ -1857,7 +1857,7 @@ fn num_floatingpoint(pool: &mut Pool, range: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_FLOATINGPOINT, PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), pool.add(alias_content), @@ -1905,7 +1905,7 @@ fn _num_integer(pool: &mut Pool, range: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_INTEGER, PoolVec::new(vec![(PoolStr::new("range", pool), range)].into_iter(), pool), pool.add(alias_content), @@ -1918,7 +1918,7 @@ fn num_num(pool: &mut Pool, type_id: TypeId) -> Type2 { let alias_content = range_type.shallow_clone(); - Type2::Alias( + Type2::Opaque( Symbol::NUM_NUM, PoolVec::new( vec![(PoolStr::new("range", pool), type_id)].into_iter(), diff --git a/ast/src/lang/core/types.rs b/ast/src/lang/core/types.rs index d65d2bb059..53d7b33314 100644 --- a/ast/src/lang/core/types.rs +++ b/ast/src/lang/core/types.rs @@ -24,6 +24,7 @@ pub enum Type2 { Variable(Variable), // 4B Alias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad + Opaque(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad AsAlias(Symbol, PoolVec<(PoolStr, TypeId)>, TypeId), // 24B = 8B + 8B + 4B + pad // 24B @@ -74,6 +75,9 @@ impl ShallowClone for Type2 { Self::Alias(symbol, args, alias_type_id) => { Self::Alias(*symbol, args.shallow_clone(), alias_type_id.clone()) } + Self::Opaque(symbol, args, alias_type_id) => { + Self::Opaque(*symbol, args.shallow_clone(), alias_type_id.clone()) + } Self::Record(fields, ext_id) => Self::Record(fields.shallow_clone(), ext_id.clone()), Self::Function(args, closure_type_id, ret_type_id) => Self::Function( args.shallow_clone(), @@ -101,7 +105,7 @@ impl Type2 { Variable(v) => { result.insert(*v); } - Alias(_, _, actual) | AsAlias(_, _, actual) => { + Alias(_, _, actual) | AsAlias(_, _, actual) | Opaque(_, _, actual) => { stack.push(pool.get(*actual)); } HostExposedAlias { diff --git a/ast/src/solve_type.rs b/ast/src/solve_type.rs index 096a405d5c..eac6ae712e 100644 --- a/ast/src/solve_type.rs +++ b/ast/src/solve_type.rs @@ -3,6 +3,7 @@ use bumpalo::Bump; use roc_can::expected::{Expected, PExpected}; use roc_collections::all::{BumpMap, BumpMapDefault, MutMap}; +use roc_error_macros::internal_error; use roc_module::ident::TagName; use roc_module::symbol::Symbol; use roc_region::all::{Loc, Region}; @@ -868,7 +869,7 @@ fn type_to_variable<'a>( register(subs, rank, pools, content) } - Alias(symbol, args, alias_type_id) => { + Alias(symbol, args, alias_type_id) | Opaque(symbol, args, alias_type_id) => { // TODO cache in uniqueness inference gives problems! all Int's get the same uniqueness var! // Cache aliases without type arguments. Commonly used aliases like `Int` would otherwise get O(n) // different variables (once for each occurrence). The recursion restriction is required @@ -910,8 +911,12 @@ fn type_to_variable<'a>( let alias_var = type_to_variable(arena, mempool, subs, rank, pools, cached, alias_type); - // TODO(opaques): take opaques into account - let content = Content::Alias(*symbol, arg_vars, alias_var, AliasKind::Structural); + let kind = match typ { + Alias(..) => AliasKind::Structural, + Opaque(..) => AliasKind::Opaque, + _ => internal_error!(), + }; + let content = Content::Alias(*symbol, arg_vars, alias_var, kind); let result = register(subs, rank, pools, content); diff --git a/compiler/solve/tests/solve_expr.rs b/compiler/solve/tests/solve_expr.rs index a8ee55ee26..8fe7a6622b 100644 --- a/compiler/solve/tests/solve_expr.rs +++ b/compiler/solve/tests/solve_expr.rs @@ -6168,4 +6168,17 @@ mod solve_expr { "a -> Task a *", ); } + + #[test] + fn list_with_num_and_str() { + infer_eq_without_problem( + indoc!( + r#" + val = [ 1, "abc" ] + val + "# + ), + "", + ) + } } diff --git a/editor/src/editor/mvc/ed_update.rs b/editor/src/editor/mvc/ed_update.rs index ba546e85d1..bbe05560c6 100644 --- a/editor/src/editor/mvc/ed_update.rs +++ b/editor/src/editor/mvc/ed_update.rs @@ -3169,7 +3169,7 @@ pub mod test_ed_update { assert_type_tooltips_clean( ovec!["val = [ [ 0, 1, \"2\" ], [ 3, 4, 5 ┃] ]"], - ovec!["List (Num *)", "List (List )"], + ovec!["List (Num *)", "List "], )?; Ok(())