Skip to content

Commit

Permalink
fix(rename): Rename implicit imports
Browse files Browse the repository at this point in the history
This caused panics on linux but not on windows since it happened that
two implicit imports, one from the implicit prelude and one from the
normal code, laid on the exact same location and got the same name. It
didn't happen on windows since I have CRLF linendings there (but it
could just as well have happened on windows and not on linux of course).
Since these bindings were never renamed they looked the same to the
compiler which then loaded the wrong variable (since the implicit
prelude essentially were shadowed).
  • Loading branch information
Marwes committed Mar 27, 2018
1 parent 1cafe4a commit 6a3409d
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions check/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,30 @@ pub fn rename(symbols: &mut SymbolModule, expr: &mut SpannedExpr<Symbol>) {
impl<'a, 'b> RenameVisitor<'a, 'b> {
fn new_pattern(&mut self, pattern: &mut ast::SpannedPattern<Symbol>) {
match pattern.value {
Pattern::Record { ref mut fields, .. } => for field in fields {
match field.value {
Some(ref mut pat) => self.new_pattern(pat),
None => {
let id = field.name.value.clone();
let pat = Pattern::Ident(TypedIdent {
name: self.stack_var(id, pattern.span),
typ: Type::hole(),
});
field.value = Some(pos::spanned(field.name.span, pat));
Pattern::Record {
ref mut fields,
ref mut implicit_import,
..
} => {
for field in fields {
match field.value {
Some(ref mut pat) => self.new_pattern(pat),
None => {
let id = field.name.value.clone();
let pat = Pattern::Ident(TypedIdent {
name: self.stack_var(id, pattern.span),
typ: Type::hole(),
});
field.value = Some(pos::spanned(field.name.span, pat));
}
}
}
},
if let Some(ref mut implicit_import) = *implicit_import {
let new_name =
self.stack_var(implicit_import.value.clone(), implicit_import.span);
implicit_import.value = new_name;
}
}
Pattern::Ident(ref mut id) => {
let new_name = self.stack_var(id.name.clone(), pattern.span);
id.name = new_name;
Expand Down

0 comments on commit 6a3409d

Please sign in to comment.