Resolver - Ensure method names are unique
This commit is contained in:
parent
77f14bfa8e
commit
39276f4756
1 changed files with 9 additions and 2 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use crate::{
|
||||
ast::{ClassMemberDecl, ExprNode, ProgramNode, StmtNode, VariableExpr},
|
||||
|
@ -273,10 +273,17 @@ fn resolve_class<'a, 'b>(
|
|||
where
|
||||
'b: 'a,
|
||||
{
|
||||
let mut names = HashSet::new();
|
||||
rs.define_this();
|
||||
methods.iter().try_for_each(|member| match member {
|
||||
ClassMemberDecl::Method(method) | ClassMemberDecl::StaticMethod(method) => rs.with_scope(
|
||||
|rs| resolve_function(rs, &method.params, &method.body),
|
||||
|rs| {
|
||||
if names.insert(method.name.lexeme.clone()) {
|
||||
resolve_function(rs, &method.params, &method.body)
|
||||
} else {
|
||||
rs.error(&method.name, "duplicate method name")
|
||||
}
|
||||
},
|
||||
if method.name.lexeme == "init" {
|
||||
ScopeType::Initializer
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue