Skip to content

Commit

Permalink
Bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
sisshiki1969 committed Jul 12, 2023
1 parent b4e026f commit 7cbda09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
6 changes: 3 additions & 3 deletions monoruby/src/executor/builtins/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ fn const_get(
) -> Result<Value> {
MonorubyErr::check_number_of_arguments_range(len, 1..=2)?;
let name = arg[0].expect_symbol_or_string(globals)?;
let class_id = lfp.self_val().as_class_id();
let module = lfp.self_val().as_class();
let v = if len == 1 || arg[1].as_bool() {
globals.search_constant_superclass(class_id, name)
globals.search_constant_superclass(module, name)
} else {
globals.get_constant(class_id, name)
globals.get_constant(module.id(), name)
};
match v {
Some(v) => Ok(v),
Expand Down
19 changes: 8 additions & 11 deletions monoruby/src/executor/globals/store/class/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ impl Globals {
self.store[class_id].constants.get(&name).cloned()
}

pub fn search_constant_superclass(
&self,
mut class_id: ClassId,
name: IdentId,
) -> Option<Value> {
pub fn search_constant_superclass(&self, mut module: Module, name: IdentId) -> Option<Value> {
loop {
match self.get_constant(class_id, name) {
match self.get_constant(module.id(), name) {
Some(v) => return Some(v),
None => match class_id.get_module(self).superclass_id() {
Some(superclass) => class_id = superclass,
None => match module.superclass() {
Some(superclass) => module = superclass,
None => break,
},
};
Expand Down Expand Up @@ -126,13 +122,14 @@ impl Globals {
if let Some(v) = self.search_lexical_stack(name, current_func) {
return Ok(v);
}
let class_id = self[current_func]
let module = self[current_func]
.as_ruby_func()
.lexical_context
.last()
.map_or(OBJECT_CLASS, |m| m.superclass_id().unwrap_or(OBJECT_CLASS));
.unwrap_or(&OBJECT_CLASS.get_module(self))
.to_owned();

match self.search_constant_superclass(class_id, name) {
match self.search_constant_superclass(module, name) {
Some(v) => Ok(v),
None => Err(MonorubyErr::uninitialized_constant(name)),
}
Expand Down
4 changes: 2 additions & 2 deletions monoruby/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ mod test {
);
run_test_error("break");
run_test_error("joke");
//run_test_error("Joke");
run_test_error("Joke");
run_test_error("91552338.chr");
run_test_error(r#"9155.."s""#);
}
Expand Down Expand Up @@ -2392,7 +2392,7 @@ mod test {
run_test(r#"defined? $a"#);
run_test(r#"$a=10; defined? $a"#);
run_test(r#"C=10; defined? C"#);
//run_test(r#"defined? C"#);
run_test(r#"defined? C"#);
run_test(r#"defined? [1,2].map{}.to_s"#);
run_test(r#"defined? [1,2].map{}.zxzxz"#);
run_test(r#"defined? a[1]"#);
Expand Down

0 comments on commit 7cbda09

Please sign in to comment.