@@ -4,6 +4,56 @@ use crate::lexer::TokenKind;
44
55pub ( crate ) fn check ( analyzer : & mut Analyzer < ' _ > ) {
66 check_operator_overload_attempts ( analyzer) ;
7+ check_implicit_conversion_attempts ( analyzer) ;
8+ }
9+
10+ fn check_implicit_conversion_attempts ( analyzer : & mut Analyzer < ' _ > ) {
11+ for index in 0 ..analyzer. tokens . len ( ) {
12+ if !analyzer. tokens [ index] . is_ident_text ( "as" ) || as_belongs_to_with ( analyzer, index) {
13+ continue ;
14+ }
15+ analyzer. diagnostics . push (
16+ Diagnostic :: error (
17+ code:: IMPLICIT_CONVERSION_ATTEMPT ,
18+ "cast-style conversions are not part of RSScript." ,
19+ analyzer. tokens [ index] . span . clone ( ) ,
20+ "implicit conversion attempt" ,
21+ )
22+ . with_cause ( "RSScript requires conversions to be explicit named APIs so review tools can see them." )
23+ . with_fix (
24+ "use_named_conversion" ,
25+ "Use a named conversion such as `Target.from(value: read source)`." ,
26+ "manual" ,
27+ ) ,
28+ ) ;
29+ }
30+ }
31+
32+ fn as_belongs_to_with ( analyzer : & Analyzer < ' _ > , as_index : usize ) -> bool {
33+ for token in analyzer. tokens [ ..as_index] . iter ( ) . rev ( ) {
34+ if token. is_ident_text ( "with" ) {
35+ return true ;
36+ }
37+ if token. symbol ( "{" )
38+ || token. symbol ( "}" )
39+ || token. is_ident_text ( "let" )
40+ || token. is_ident_text ( "local" )
41+ || token. is_ident_text ( "return" )
42+ || token. is_ident_text ( "fn" )
43+ || token. is_ident_text ( "class" )
44+ || token. is_ident_text ( "struct" )
45+ || token. is_ident_text ( "resource" )
46+ || token. is_ident_text ( "if" )
47+ || token. is_ident_text ( "else" )
48+ || token. is_ident_text ( "loop" )
49+ || token. is_ident_text ( "while" )
50+ || token. is_ident_text ( "break" )
51+ || token. is_ident_text ( "continue" )
52+ {
53+ return false ;
54+ }
55+ }
56+ false
757}
858
959fn check_operator_overload_attempts ( analyzer : & mut Analyzer < ' _ > ) {
0 commit comments