Solve derived impls

This commit is contained in:
Ayaz Hafiz 2022-05-19 11:09:31 -04:00
parent c5d970bd81
commit 95e325296f
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 12 additions and 28 deletions

View file

@ -908,7 +908,7 @@ fn canonicalize_has_clause(
var_store: &mut VarStore, var_store: &mut VarStore,
introduced_variables: &mut IntroducedVariables, introduced_variables: &mut IntroducedVariables,
clause: &Loc<roc_parse::ast::HasClause<'_>>, clause: &Loc<roc_parse::ast::HasClause<'_>>,
abilities_in_scope: &[Symbol], abilities_in_local_scope: &[Symbol],
references: &mut VecSet<Symbol>, references: &mut VecSet<Symbol>,
) -> Result<(), Type> { ) -> Result<(), Type> {
let Loc { let Loc {
@ -927,7 +927,12 @@ fn canonicalize_has_clause(
let ability = match ability.value { let ability = match ability.value {
TypeAnnotation::Apply(module_name, ident, _type_arguments) => { TypeAnnotation::Apply(module_name, ident, _type_arguments) => {
let symbol = make_apply_symbol(env, ability.region, scope, module_name, ident)?; let symbol = make_apply_symbol(env, ability.region, scope, module_name, ident)?;
if !abilities_in_scope.contains(&symbol) {
// Ability defined locally, whose members we are constructing right now...
if !abilities_in_local_scope.contains(&symbol)
// or an ability that was imported from elsewhere
&& !scope.abilities_store.is_ability(symbol)
{
let region = ability.region; let region = ability.region;
env.problem(roc_problem::can::Problem::HasClauseIsNotAbility { region }); env.problem(roc_problem::can::Problem::HasClauseIsNotAbility { region });
return Err(Type::Erroneous(Problem::HasClauseIsNotAbility(region))); return Err(Type::Erroneous(Problem::HasClauseIsNotAbility(region)));

View file

@ -255,12 +255,12 @@ pub fn canonicalize_module_defs<'a>(
{ {
// These are not aliases but Apply's and we make sure they are always in scope // These are not aliases but Apply's and we make sure they are always in scope
} else { } else {
// This is a type alias // This is a type alias or ability
// the symbol should already be added to the scope when this module is canonicalized // the symbol should already be added to the scope when this module is canonicalized
debug_assert!( debug_assert!(
scope.contains_alias(symbol), scope.contains_alias(symbol) || scope.abilities_store.is_ability(symbol),
"The {:?} is not a type alias known in {:?}", "The {:?} is not a type alias or ability known in {:?}",
symbol, symbol,
home home
); );

View file

@ -6457,7 +6457,6 @@ mod solve_expr {
} }
#[test] #[test]
#[ignore]
fn encode_record() { fn encode_record() {
infer_queries( infer_queries(
indoc!( indoc!(
@ -6470,31 +6469,11 @@ mod solve_expr {
# ^^^^^^^^^ # ^^^^^^^^^
"# "#
), ),
&[], &["Encoding#toEncoder : { a : Str } -> Encoder fmt | fmt has EncoderFormatting"],
) )
} }
#[test] #[test]
#[ignore]
fn encode_record_with_nested_able_var() {
infer_queries(
indoc!(
r#"
app "test"
imports [ Encode.{ toEncoder, Encoding } ]
provides [ main ] to "./platform"
main : a -> _ | a has Encoding
main = \a -> toEncoder { a: a }
# ^^^^^^^^^
"#
),
&[],
)
}
#[test]
#[ignore]
fn encode_record_with_nested_custom_impl() { fn encode_record_with_nested_custom_impl() {
infer_queries( infer_queries(
indoc!( indoc!(
@ -6510,7 +6489,7 @@ mod solve_expr {
# ^^^^^^^^^ # ^^^^^^^^^
"# "#
), ),
&[], &["Encoding#toEncoder : { a : A } -> Encoder fmt | fmt has EncoderFormatting"],
) )
} }
} }