- commit
- aad8fd0
- parent
- 87ad01e
- author
- xplshn
- date
- 2025-09-10 22:38:29 +0000 UTC
remove some warnings Signed-off-by: xplshn <[email protected]>
2 files changed,
+10,
-11
+2,
-0
1@@ -1,5 +1,6 @@
2 .*
3 *.o
4+*.out
5 output.*
6 lib/qbe/obj
7 ./cbc
8@@ -12,3 +13,4 @@ tests/.build
9 output_*
10 ./cmd/gtest/gtest
11 ./cmd/gbc/gbc
12+./gbc
+8,
-11
1@@ -1114,14 +1114,12 @@ func (tc *TypeChecker) getBinaryOpResultType(op token.Type, left, right *ast.BxT
2
3 // For untyped + untyped, emit warning
4 if leftIsLiteral && rightIsLiteral {
5- // Both are literals, use DebugComp warning
6 if tc.cfg.IsWarningEnabled(config.WarnDebugComp) {
7 util.Warn(tc.cfg, config.WarnDebugComp, tok, "Operation between untyped operands")
8 }
9 } else {
10- // At least one is not a literal, use prom-types warning
11 if tc.cfg.IsWarningEnabled(config.WarnPromTypes) {
12- util.Warn(tc.cfg, config.WarnPromTypes, tok, "Operation between untyped operands")
13+ util.Warn(tc.cfg, config.WarnDebugComp, tok, "Operation between untyped operands")
14 }
15 }
16 // Default to int type for untyped operations
17@@ -1138,14 +1136,14 @@ func (tc *TypeChecker) getBinaryOpResultType(op token.Type, left, right *ast.BxT
18 leftIsLiteral := leftNode != nil && (leftNode.Type == ast.Number || leftNode.Type == ast.FloatNumber)
19
20 if leftIsLiteral {
21- // Literal promotion, use DebugComp warning
22 if tc.cfg.IsWarningEnabled(config.WarnDebugComp) {
23 util.Warn(tc.cfg, config.WarnDebugComp, tok, "Untyped operand promoted to '%s'", ast.TypeToString(rType))
24 }
25 } else {
26- // Variable promotion, use prom-types warning
27 if tc.cfg.IsWarningEnabled(config.WarnPromTypes) {
28- util.Warn(tc.cfg, config.WarnPromTypes, tok, "Untyped operand promoted to '%s'", ast.TypeToString(rType))
29+ if rType.Kind != ast.TYPE_UNTYPED {
30+ util.Warn(tc.cfg, config.WarnPromTypes, tok, "Untyped operand promoted to '%s'", ast.TypeToString(rType))
31+ }
32 }
33 }
34 }
35@@ -1158,13 +1156,11 @@ func (tc *TypeChecker) getBinaryOpResultType(op token.Type, left, right *ast.BxT
36 rightIsLiteral := rightNode != nil && (rightNode.Type == ast.Number || rightNode.Type == ast.FloatNumber)
37
38 if rightIsLiteral {
39- // Literal promotion, use DebugComp warning
40 if tc.cfg.IsWarningEnabled(config.WarnDebugComp) {
41 util.Warn(tc.cfg, config.WarnDebugComp, tok, "Untyped operand promoted to '%s'", ast.TypeToString(lType))
42 }
43 } else {
44- // Variable promotion, use prom-types warning
45- if tc.cfg.IsWarningEnabled(config.WarnPromTypes) {
46+ if lType.Kind != ast.TYPE_UNTYPED {
47 util.Warn(tc.cfg, config.WarnPromTypes, tok, "Untyped operand promoted to '%s'", ast.TypeToString(lType))
48 }
49 }
50@@ -1214,13 +1210,14 @@ func (tc *TypeChecker) getBinaryOpResultType(op token.Type, left, right *ast.BxT
51 if op == token.Minus && resLeft.Kind == ast.TYPE_POINTER && resRight.Kind == ast.TYPE_POINTER {
52 return ast.TypeInt
53 }
54- // Allow string concatenation: byte* + byte* -> byte* (for Plus operation only)
55+ // Allow string concatenation: *byte + *byte -> *byte | (+ only)
56 if op == token.Plus && resLeft.Kind == ast.TYPE_POINTER && resRight.Kind == ast.TYPE_POINTER &&
57 resLeft.Base != nil && resRight.Base != nil &&
58 resLeft.Base.Kind == ast.TYPE_PRIMITIVE && resLeft.Base.Name == "byte" &&
59 resRight.Base.Kind == ast.TYPE_PRIMITIVE && resRight.Base.Name == "byte" {
60 return resLeft
61 }
62+ // TODO: Support othe array types
63 }
64
65 tc.typeErrorOrWarn(tok, "Invalid binary operation between types '%s' and '%s'", ast.TypeToString(left), ast.TypeToString(right))
66@@ -1352,4 +1349,4 @@ func (tc *TypeChecker) isScalarType(t *ast.BxType) bool {
67 if t == nil { return false }
68 resolved := tc.resolveType(t)
69 return tc.isNumericType(resolved) || resolved.Kind == ast.TYPE_POINTER || resolved.Kind == ast.TYPE_BOOL
70-}
71+}