mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
fix: visibility bug
This commit is contained in:
parent
0d43299cce
commit
62b06022cb
6 changed files with 23 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
from _erg_result import is_ok
|
||||
from _erg_range import Range
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
def in_operator(elem, y):
|
||||
if type(y) == type:
|
||||
|
@ -18,6 +19,8 @@ def in_operator(elem, y):
|
|||
len_check = len(elem) == len(y)
|
||||
return type_check and len_check
|
||||
elif isinstance(y, tuple):
|
||||
if not hasattr(elem, "__iter__"):
|
||||
return False
|
||||
type_check = all(map(lambda x: in_operator(x[0], x[1]), zip(elem, y)))
|
||||
len_check = len(elem) == len(y)
|
||||
return type_check and len_check
|
||||
|
|
|
@ -54,7 +54,7 @@ fn demangle(name: &str) -> String {
|
|||
}
|
||||
|
||||
// TODO:
|
||||
fn replace_non_symbolic(name: String) -> String {
|
||||
fn replace_non_symbolic(name: &str) -> String {
|
||||
name.replace('\'', "__single_quote__")
|
||||
.replace(' ', "__space__")
|
||||
.replace('+', "__plus__")
|
||||
|
@ -789,7 +789,7 @@ impl ScriptGenerator {
|
|||
return demangle(&py_name);
|
||||
}
|
||||
let name = ident.inspect().to_string();
|
||||
let name = replace_non_symbolic(name);
|
||||
let name = replace_non_symbolic(&name);
|
||||
if ident.vis().is_public() {
|
||||
name
|
||||
} else {
|
||||
|
@ -802,7 +802,7 @@ impl ScriptGenerator {
|
|||
for non_default in params.non_defaults {
|
||||
match non_default.raw.pat {
|
||||
ParamPattern::VarName(param) => {
|
||||
code += &format!("{}__,", param.into_token().content);
|
||||
code += &format!("{}__,", replace_non_symbolic(¶m.into_token().content));
|
||||
}
|
||||
ParamPattern::Discard(_) => {
|
||||
code += &format!("_{},", self.fresh_var_n);
|
||||
|
@ -815,7 +815,7 @@ impl ScriptGenerator {
|
|||
let ParamPattern::VarName(param) = default.sig.raw.pat else { todo!() };
|
||||
code += &format!(
|
||||
"{}__ = {},",
|
||||
param.into_token().content,
|
||||
replace_non_symbolic(¶m.into_token().content),
|
||||
self.transpile_expr(default.default_val)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1003,6 +1003,10 @@ impl Desugarer {
|
|||
let mut attrs = RecordAttrs::new(vec![]);
|
||||
let mut tys = vec![];
|
||||
for ParamRecordAttr { lhs, rhs } in rec.elems.iter() {
|
||||
let lhs = Identifier {
|
||||
vis: VisModifierSpec::Public(Token::DUMMY),
|
||||
..lhs.clone()
|
||||
};
|
||||
let infer = Token::new(TokenKind::Try, "?", line, 0);
|
||||
let expr = rhs
|
||||
.t_spec
|
||||
|
@ -1193,11 +1197,15 @@ impl Desugarer {
|
|||
let mut attrs = RecordAttrs::new(vec![]);
|
||||
let mut tys = vec![];
|
||||
for ParamRecordAttr { lhs, rhs } in rec.elems.iter_mut() {
|
||||
let lhs = Identifier {
|
||||
vis: VisModifierSpec::Public(Token::DUMMY),
|
||||
..lhs.clone()
|
||||
};
|
||||
insertion_idx = self.desugar_nested_param_pattern(
|
||||
new_body,
|
||||
rhs,
|
||||
&buf_name,
|
||||
BufIndex::Record(lhs),
|
||||
BufIndex::Record(&lhs),
|
||||
insertion_idx,
|
||||
);
|
||||
let infer = Token::new(TokenKind::Try, "?", line, 0);
|
||||
|
|
|
@ -13,7 +13,7 @@ if! cond:
|
|||
a = [1, 2, 3]
|
||||
sum = match a:
|
||||
[x, y, z] -> x + y + z
|
||||
(x, y, z) -> x + y + z
|
||||
((x, y, z),) -> x + y + z
|
||||
{x; y; z} -> x + y + z
|
||||
(i: Int) -> i
|
||||
_ -> panic "unknown object"
|
||||
|
|
|
@ -31,3 +31,8 @@ public = { .x = 1; .y = 2 }
|
|||
|
||||
_ = unpack public # OK
|
||||
_ = unpack private # ERR
|
||||
|
||||
unpack2 {x; y} = x + y
|
||||
|
||||
_ = unpack2 public # OK
|
||||
_ = unpack2 private # ERR
|
||||
|
|
|
@ -334,7 +334,7 @@ fn exec_var_args_err() -> Result<(), ()> {
|
|||
|
||||
#[test]
|
||||
fn exec_visibility() -> Result<(), ()> {
|
||||
expect_failure("tests/should_err/visibility.er", 2, 6)
|
||||
expect_failure("tests/should_err/visibility.er", 2, 7)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue