diff --git a/compiler/erg_compiler/context/initialize/mod.rs b/compiler/erg_compiler/context/initialize/mod.rs index 24f2f1c0..2a83992e 100644 --- a/compiler/erg_compiler/context/initialize/mod.rs +++ b/compiler/erg_compiler/context/initialize/mod.rs @@ -2035,7 +2035,8 @@ impl Context { vec![kw("iterable", poly("Iterable", vec![ty_tp(T.clone())]))], None, array_t(T.clone(), TyParam::erased(Nat)), - ); + ) + .quantify(); let t_str = nd_func(vec![kw("object", Obj)], None, Str); let A = mono_q("A", Constraint::Uninited); let A = mono_q("A", subtypeof(poly("Add", vec![ty_tp(A)]))); diff --git a/compiler/erg_compiler/error.rs b/compiler/erg_compiler/error.rs index 5875ef41..5efb5f5c 100644 --- a/compiler/erg_compiler/error.rs +++ b/compiler/erg_compiler/error.rs @@ -1995,64 +1995,6 @@ impl LowerError { ) } - pub fn unused_warning( - input: Input, - errno: usize, - loc: Location, - name: &str, - caused_by: String, - ) -> Self { - let name = StyledString::new(readable_name(name), Some(WARN), Some(ATTR)); - Self::new( - ErrorCore::new( - vec![SubMessage::only_loc(loc)], - switch_lang!( - "japanese" => format!("{name}は使用されていません"), - "simplified_chinese" => format!("{name}未使用"), - "traditional_chinese" => format!("{name}未使用"), - "english" => format!("{name} is not used"), - ), - errno, - UnusedWarning, - loc, - ), - input, - caused_by, - ) - } - - pub fn union_return_type_warning( - input: Input, - errno: usize, - loc: Location, - caused_by: String, - fn_name: &str, - typ: &Type, - ) -> Self { - let hint = switch_lang!( - "japanese" => format!("`{fn_name}(...): {typ} = ...`など明示的に戻り値型を指定してください"), - "simplified_chinese" => format!("请明确指定函数{fn_name}的返回类型,例如`{fn_name}(...): {typ} = ...`"), - "traditional_chinese" => format!("請明確指定函數{fn_name}的返回類型,例如`{fn_name}(...): {typ} = ...`"), - "english" => format!("please explicitly specify the return type of function {fn_name}, for example `{fn_name}(...): {typ} = ...`"), - ); - LowerError::new( - ErrorCore::new( - vec![SubMessage::ambiguous_new(loc, vec![], Some(hint))], - switch_lang!( - "japanese" => format!("関数{fn_name}の戻り値型が単一ではありません"), - "simplified_chinese" => format!("函数{fn_name}的返回类型不是单一的"), - "traditional_chinese" => format!("函數{fn_name}的返回類型不是單一的"), - "english" => format!("the return type of function {fn_name} is not single"), - ), - errno, - TypeWarning, - loc, - ), - input, - caused_by, - ) - } - pub fn del_error(input: Input, errno: usize, ident: &Identifier, caused_by: String) -> Self { let name = StyledString::new(readable_name(ident.inspect()), Some(WARN), Some(ATTR)); Self::new( @@ -2476,6 +2418,92 @@ impl LowerError { } } +impl LowerWarning { + pub fn unused_warning( + input: Input, + errno: usize, + loc: Location, + name: &str, + caused_by: String, + ) -> Self { + let name = StyledString::new(readable_name(name), Some(WARN), Some(ATTR)); + Self::new( + ErrorCore::new( + vec![SubMessage::only_loc(loc)], + switch_lang!( + "japanese" => format!("{name}は使用されていません"), + "simplified_chinese" => format!("{name}未使用"), + "traditional_chinese" => format!("{name}未使用"), + "english" => format!("{name} is not used"), + ), + errno, + UnusedWarning, + loc, + ), + input, + caused_by, + ) + } + + pub fn union_return_type_warning( + input: Input, + errno: usize, + loc: Location, + caused_by: String, + fn_name: &str, + typ: &Type, + ) -> Self { + let hint = switch_lang!( + "japanese" => format!("`{fn_name}(...): {typ} = ...`など明示的に戻り値型を指定してください"), + "simplified_chinese" => format!("请明确指定函数{fn_name}的返回类型,例如`{fn_name}(...): {typ} = ...`"), + "traditional_chinese" => format!("請明確指定函數{fn_name}的返回類型,例如`{fn_name}(...): {typ} = ...`"), + "english" => format!("please explicitly specify the return type of function {fn_name}, for example `{fn_name}(...): {typ} = ...`"), + ); + LowerError::new( + ErrorCore::new( + vec![SubMessage::ambiguous_new(loc, vec![], Some(hint))], + switch_lang!( + "japanese" => format!("関数{fn_name}の戻り値型が単一ではありません"), + "simplified_chinese" => format!("函数{fn_name}的返回类型不是单一的"), + "traditional_chinese" => format!("函數{fn_name}的返回類型不是單一的"), + "english" => format!("the return type of function {fn_name} is not single"), + ), + errno, + TypeWarning, + loc, + ), + input, + caused_by, + ) + } + + pub fn builtin_exists_warning( + input: Input, + errno: usize, + loc: Location, + caused_by: String, + name: &str, + ) -> Self { + let name = StyledStr::new(readable_name(name), Some(WARN), Some(ATTR)); + Self::new( + ErrorCore::new( + vec![SubMessage::only_loc(loc)], + switch_lang!( + "japanese" => format!("同名の組み込み関数{name}が既に存在します"), + "simplified_chinese" => format!("已存在同名的内置函数{name}"), + "traditional_chinese" => format!("已存在同名的內置函數{name}"), + "english" => format!("a built-in function named {name} already exists"), + ), + errno, + NameWarning, + loc, + ), + input, + caused_by, + ) + } +} + #[derive(Debug, Clone)] pub struct CompileErrors(Vec); diff --git a/compiler/erg_compiler/lower.rs b/compiler/erg_compiler/lower.rs index b03efcd5..17fa2259 100644 --- a/compiler/erg_compiler/lower.rs +++ b/compiler/erg_compiler/lower.rs @@ -1059,6 +1059,19 @@ impl ASTLowerer { self.ctx.caused_by(), &name, ))); + } else if self + .ctx + .get_builtins() + .and_then(|ctx| ctx.get_var_info(&name)) + .is_some() + { + self.warns.push(LowerWarning::builtin_exists_warning( + self.cfg.input.clone(), + line!() as usize, + def.sig.loc(), + self.ctx.caused_by(), + &name, + )); } let kind = ContextKind::from(def.def_kind()); let vis = def.sig.vis();