-
-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathwarn.rs
133 lines (128 loc) · 3.77 KB
/
warn.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use erg_common::error::{ErrorCore, ErrorKind, Location, SubMessage};
use erg_common::io::Input;
use erg_common::switch_lang;
use erg_common::traits::NoTypeDisplay;
use erg_compiler::error::CompileWarning;
use erg_compiler::hir::Expr;
pub(crate) fn too_many_params(input: Input, caused_by: String, loc: Location) -> CompileWarning {
CompileWarning::new(
ErrorCore::new(
vec![],
"too many parameters".to_string(),
0,
ErrorKind::Warning,
loc,
),
input,
caused_by,
)
}
pub(crate) fn tautology(
input: Input,
errno: usize,
caused_by: String,
loc: Location,
expr: Expr,
) -> CompileWarning {
let msg = switch_lang!(
"japanese" => "比較演算子が冗長です",
"simplified_chinese" => "比较运算符是多余的",
"traditional_chinese" => "比較運算符號是多餘的",
"english" => "comparison operator is verbose",
)
.to_string();
let hint = switch_lang!(
"japanese" => format!("より簡潔に書きましょう: {}", expr.to_string_notype()),
"simplified_chinese" => format!("更简洁地写作: {}", expr.to_string_notype()),
"traditional_chinese" => format!("寫作更簡潔: {}", expr.to_string_notype()),
"english" => format!("write more succinctly: {}", expr.to_string_notype()),
)
.to_string();
CompileWarning::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(loc, vec![], Some(hint))],
msg,
errno,
ErrorKind::Warning,
loc,
),
input,
caused_by,
)
}
pub(crate) fn too_many_instance_attributes(
input: Input,
errno: usize,
caused_by: String,
loc: Location,
) -> CompileWarning {
let msg = switch_lang!(
"japanese" => "インスタンス属性が多すぎます",
"simplified_chinese" => "实例属性过多",
"traditional_chinese" => "實例屬性過多",
"english" => "too many instance attributes",
)
.to_string();
let hint = switch_lang!(
"japanese" => "サブクラスやデータクラスを活用してください",
"simplified_chinese" => "利用子类和数据类",
"traditional_chinese" => "利用子類和資料類",
"english" => "take advantage of subclasses or data classes",
)
.to_string();
CompileWarning::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(loc, vec![], Some(hint))],
msg,
errno,
ErrorKind::AttributeWarning,
loc,
),
input,
caused_by,
)
}
pub(crate) fn true_comparison(
expr: &Expr,
input: Input,
caused_by: String,
loc: Location,
) -> CompileWarning {
CompileWarning::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(
loc,
vec![],
Some(format!("just write: {}", expr.to_string_notype())),
)],
"equality checks against True are redundant".to_string(),
0,
ErrorKind::Warning,
loc,
),
input,
caused_by,
)
}
pub(crate) fn false_comparison(
expr: &Expr,
input: Input,
caused_by: String,
loc: Location,
) -> CompileWarning {
CompileWarning::new(
ErrorCore::new(
vec![SubMessage::ambiguous_new(
loc,
vec![],
Some(format!("just write: not {}", expr.to_string_notype())),
)],
"equality checks against False are redundant".to_string(),
0,
ErrorKind::Warning,
loc,
),
input,
caused_by,
)
}