Skip to content

Commit

Permalink
fix: Don't use the empty span in derive macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Dec 29, 2020
1 parent c904189 commit d05f1ca
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions vm/src/derive/deserialize.rs
Expand Up @@ -153,6 +153,7 @@ pub fn generate<'ast>(
typ: Some(binding_type(
arena,
symbols,
span,
"Deserialize",
self_type(),
bind,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/derive/eq.rs
Expand Up @@ -220,7 +220,7 @@ pub fn generate<'ast>(
args: &mut [],
expr: pos::spanned(span, eq_record_expr),
metadata: Default::default(),
typ: Some(binding_type(arena, symbols, "Eq", self_type(), bind)),
typ: Some(binding_type(arena, symbols, span, "Eq", self_type(), bind)),
resolved_type: Type::hole(),
})
}
11 changes: 9 additions & 2 deletions vm/src/derive/mod.rs
Expand Up @@ -286,13 +286,14 @@ fn is_self_type(self_: &Symbol, typ: &AstType<Symbol>) -> bool {
fn binding_type<'ast>(
arena: ast::ArenaRef<'_, 'ast, Symbol>,
symbols: &mut Symbols,
span: Span<BytePos>,
derive_type_name: &str,
self_type: AstType<'ast, Symbol>,
bind: &TypeBinding<'ast, Symbol>,
) -> AstType<'ast, Symbol> {
let derive_symbol = symbols.simple_symbol(derive_type_name);
let derive_type = move || arena.clone().ident(KindedIdent::new(derive_symbol.clone()));
arena.clone().function_implicit(
let mut typ = arena.clone().function_implicit(
bind.alias.value.params().iter().cloned().map(|g| {
TypeContext::app(
&mut arena.clone(),
Expand All @@ -305,5 +306,11 @@ fn binding_type<'ast>(
derive_type(),
arena.clone().alloc_extend(Some(self_type)),
),
)
);

crate::base::types::walk_type_mut(&mut typ, &mut |typ: &mut AstType<_>| {
*typ.span_mut() = span;
});

typ
}
9 changes: 8 additions & 1 deletion vm/src/derive/serialize.rs
Expand Up @@ -222,7 +222,14 @@ pub fn generate<'ast>(
args: &mut [],
expr: serializer_record_expr,
metadata: Default::default(),
typ: Some(binding_type(arena, symbols, "Serialize", self_type(), bind)),
typ: Some(binding_type(
arena,
symbols,
span,
"Serialize",
self_type(),
bind,
)),
resolved_type: Type::hole(),
})
}
9 changes: 8 additions & 1 deletion vm/src/derive/show.rs
Expand Up @@ -204,7 +204,14 @@ pub fn generate<'ast>(
args: &mut [],
expr: pos::spanned(span, show_record_expr),
metadata: Default::default(),
typ: Some(binding_type(arena, symbols, "Show", self_type(), bind)),
typ: Some(binding_type(
arena,
symbols,
span,
"Show",
self_type(),
bind,
)),
resolved_type: Type::hole(),
})
}

0 comments on commit d05f1ca

Please sign in to comment.