@abaplint/core 2.120.111 → 2.120.112

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ const loop_group_by_component_1 = require("./loop_group_by_component");
9
9
  class LoopGroupBy extends combi_1.Expression {
10
10
  getRunnable() {
11
11
  const components = (0, combi_1.seq)((0, combi_1.tok)(tokens_1.WParenLeftW), (0, combi_1.plus)(loop_group_by_component_1.LoopGroupByComponent), (0, combi_1.tok)(tokens_1.WParenRightW));
12
- const ret = (0, combi_1.seq)((0, combi_1.alt)(source_1.Source, components), (0, combi_1.optPrio)("ASCENDING"), (0, combi_1.optPrio)("WITHOUT MEMBERS"), loop_group_by_target_1.LoopGroupByTarget);
12
+ const ret = (0, combi_1.seq)((0, combi_1.alt)(source_1.Source, components), (0, combi_1.optPrio)((0, combi_1.seq)((0, combi_1.alt)("ASCENDING", "DESCENDING"), (0, combi_1.optPrio)("AS TEXT"))), (0, combi_1.optPrio)("WITHOUT MEMBERS"), loop_group_by_target_1.LoopGroupByTarget);
13
13
  return ret;
14
14
  }
15
15
  }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.BuiltInCall = void 0;
37
+ const Expressions = __importStar(require("../2_statements/expressions"));
38
+ const nodes_1 = require("../nodes");
39
+ const _builtin_1 = require("./_builtin");
40
+ const _object_oriented_1 = require("./_object_oriented");
41
+ const basic_1 = require("../types/basic");
42
+ class BuiltInCall {
43
+ // the call of a built-in function that starts a method call chain, not hidden by a method of the same name
44
+ static fromChain(chain, input) {
45
+ if (chain === undefined || !(chain.get() instanceof Expressions.MethodCallChain)) {
46
+ return undefined;
47
+ }
48
+ const call = chain.getChildren()[0];
49
+ if (!(call instanceof nodes_1.ExpressionNode) || !(call.get() instanceof Expressions.MethodCall)) {
50
+ return undefined;
51
+ }
52
+ const name = this.callName(call);
53
+ // upper case, the definition is cached with the name it is first searched with
54
+ if (name === undefined || _builtin_1.BuiltIn.searchBuiltin(name.toUpperCase()) === undefined) {
55
+ return undefined;
56
+ }
57
+ const enclosing = input.scope.findClassDefinition(input.scope.getEnclosingClassName());
58
+ if (enclosing !== undefined && new _object_oriented_1.ObjectOriented(input.scope).searchMethodName(enclosing, name).method !== undefined) {
59
+ return undefined;
60
+ }
61
+ return call;
62
+ }
63
+ // the call of a built-in function when the source is exactly that one call
64
+ static fromSource(source, input) {
65
+ const chain = source === null || source === void 0 ? void 0 : source.getChildren();
66
+ if ((chain === null || chain === void 0 ? void 0 : chain.length) !== 1 || !(chain[0] instanceof nodes_1.ExpressionNode) || chain[0].getChildren().length !== 1) {
67
+ return undefined;
68
+ }
69
+ return this.fromChain(chain[0], input);
70
+ }
71
+ static callName(call) {
72
+ var _a;
73
+ return (_a = call.findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
74
+ }
75
+ static isNumeric(call) {
76
+ var _a, _b, _c;
77
+ const returning = (_c = (_b = _builtin_1.BuiltIn.searchBuiltin((_a = this.callName(call)) === null || _a === void 0 ? void 0 : _a.toUpperCase())) === null || _b === void 0 ? void 0 : _b.getParameters().getReturning()) === null || _c === void 0 ? void 0 : _c.getType();
78
+ return returning instanceof basic_1.IntegerType || returning instanceof basic_1.FloatType || returning instanceof basic_1.DecFloat34Type;
79
+ }
80
+ // the call has a single argument, without a parameter name, that is a data object and not an expression
81
+ static hasDataObjectArgument(call) {
82
+ var _a;
83
+ const argument = (_a = call.findDirectExpression(Expressions.MethodCallParam)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Source);
84
+ const children = (argument === null || argument === void 0 ? void 0 : argument.getChildren()) || [];
85
+ // a literal or a text symbol, text-001
86
+ if (children.length === 1
87
+ && (children[0].get() instanceof Expressions.Constant || children[0].get() instanceof Expressions.TextElement)) {
88
+ return true;
89
+ }
90
+ // a field, a component, an offset/length or a dereference, r->*
91
+ return children.length > 0
92
+ && children[0].get() instanceof Expressions.FieldChain
93
+ && children.every(c => c.get() instanceof Expressions.FieldChain || c.get() instanceof Expressions.Dereference)
94
+ && (argument === null || argument === void 0 ? void 0 : argument.findFirstExpression(Expressions.TableExpression)) === undefined;
95
+ }
96
+ }
97
+ exports.BuiltInCall = BuiltInCall;
98
+ //# sourceMappingURL=_builtin_call.js.map
@@ -241,6 +241,17 @@ class ObjectOriented {
241
241
  }
242
242
  return undefined;
243
243
  }
244
+ // RAISE EXCEPTION and THROW are not allowed in a method whose interface declares classic EXCEPTIONS,
245
+ // not even for a CX_NO_CHECK class
246
+ checkClassBasedException() {
247
+ var _a;
248
+ const methodName = this.scope.getEnclosingMethodName();
249
+ const classDef = this.scope.findClassDefinition(this.scope.getEnclosingClassName());
250
+ if (methodName && classDef && ((_a = this.searchMethodName(classDef, methodName).method) === null || _a === void 0 ? void 0 : _a.getExceptions().length)) {
251
+ return "Old exceptions and class-based exceptions cannot be used at the same time";
252
+ }
253
+ return undefined;
254
+ }
244
255
  // SUPER-> can only call the previous implementation of the method it is used in, returns the message otherwise
245
256
  // both names are resolved in the super class, so an alias and the method it stands for are the same
246
257
  checkSuperCall(superDef, methodName) {
@@ -544,6 +544,11 @@ class BasicTypes {
544
544
  if (text === undefined) {
545
545
  text = "TYPE";
546
546
  }
547
+ const additionIssue = this.checkLengthDecimals(node, text);
548
+ if (additionIssue !== undefined) {
549
+ this.input.issues.push(additionIssue);
550
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
551
+ }
547
552
  let found = undefined;
548
553
  if (this.isRAPTypeStructure(text)) {
549
554
  return Types.VoidType.get((_f = node.findFirstExpression(Expressions.TypeStructure)) === null || _f === void 0 ? void 0 : _f.concatTokens());
@@ -1087,6 +1092,31 @@ class BasicTypes {
1087
1092
  }
1088
1093
  throw new Error("findValue, unexpected");
1089
1094
  }
1095
+ // the LENGTH and DECIMALS additions of DATA, TYPES, CONSTANTS and STATICS, as a system checks them:
1096
+ // LENGTH only with TYPE c, n, x or p, DECIMALS only with TYPE p, also not without a TYPE addition,
1097
+ // a named type cannot be given a length either. With LIKE, a system ignores LENGTH and rejects DECIMALS
1098
+ checkLengthDecimals(node, text) {
1099
+ const length = node.findDirectExpression(Expressions.Length);
1100
+ const decimals = node.findDirectExpression(Expressions.Decimals);
1101
+ if (length === undefined && decimals === undefined) {
1102
+ return undefined;
1103
+ }
1104
+ else if (text.startsWith("LIKE")) {
1105
+ if (decimals === undefined) {
1106
+ return undefined;
1107
+ }
1108
+ const message = "When referencing another field (with LIKE), type and length cannot be changed";
1109
+ return (0, _syntax_input_1.syntaxIssue)(this.input, decimals.getFirstToken(), message);
1110
+ }
1111
+ const builtin = text.startsWith("TYPE") ? text.substring(4).trim() : "";
1112
+ if (length !== undefined && ["C", "N", "X", "P"].includes(builtin) === false) {
1113
+ return (0, _syntax_input_1.syntaxIssue)(this.input, length.getFirstToken(), "\"LENGTH\" can only be specified for types C, N, X, or P");
1114
+ }
1115
+ else if (decimals !== undefined && builtin !== "P") {
1116
+ return (0, _syntax_input_1.syntaxIssue)(this.input, decimals.getFirstToken(), "\"DECIMALS\" can be specified only for type P");
1117
+ }
1118
+ return undefined;
1119
+ }
1090
1120
  findDecimals(node) {
1091
1121
  var _a, _b, _c;
1092
1122
  const dec = (_b = (_a = node.findDirectExpression(Expressions.Decimals)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Integer)) === null || _b === void 0 ? void 0 : _b.concatTokens();
@@ -52,7 +52,7 @@ function substringType(context, offset, length, node, input) {
52
52
  return context;
53
53
  }
54
54
  else if (numericName !== undefined) {
55
- const message = `Offset or length specification not possible on a field of numeric type "${numericName}"`;
55
+ const message = `Field type "${numericName}" does not permit substrings to be accessed`;
56
56
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
57
57
  return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
58
58
  }
@@ -81,12 +81,13 @@ function substringType(context, offset, length, node, input) {
81
81
  }
82
82
  return context;
83
83
  }
84
+ // the internal type code the ABAP syntax check names: I, 8, P, F, a (decfloat16), e (decfloat34)
84
85
  function numericTypeName(context) {
85
86
  if (context instanceof basic_1.IntegerType) {
86
87
  return "I";
87
88
  }
88
89
  else if (context instanceof basic_1.Integer8Type) {
89
- return "INT8";
90
+ return "8";
90
91
  }
91
92
  else if (context instanceof basic_1.PackedType) {
92
93
  return "P";
@@ -95,10 +96,10 @@ function numericTypeName(context) {
95
96
  return "F";
96
97
  }
97
98
  else if (context instanceof basic_1.DecFloat16Type) {
98
- return "DECFLOAT16";
99
+ return "a";
99
100
  }
100
101
  else if (context instanceof basic_1.DecFloat34Type) {
101
- return "DECFLOAT34";
102
+ return "e";
102
103
  }
103
104
  else if (context instanceof basic_1.DecFloatType) {
104
105
  return "DECFLOAT";
@@ -43,12 +43,20 @@ const _syntax_input_1 = require("../_syntax_input");
43
43
  const basic_1 = require("../../types/basic");
44
44
  const _type_utils_1 = require("../_type_utils");
45
45
  const _builtin_1 = require("../_builtin");
46
- const _object_oriented_1 = require("../_object_oriented");
46
+ const _builtin_call_1 = require("../_builtin_call");
47
47
  class Compare {
48
48
  static runSyntax(node, input) {
49
49
  var _a;
50
- const sourceTypes = [];
51
50
  const sources = node.findDirectExpressions(Expressions.Source);
51
+ // reported before the operands are checked, which then skip the more general predicate function message
52
+ const initialMessage = this.checkInitialOperand(node, input);
53
+ const predicateMessage = this.checkPredicateOperand(sources, input);
54
+ const operandMessage = initialMessage !== null && initialMessage !== void 0 ? initialMessage : predicateMessage;
55
+ if (operandMessage !== undefined) {
56
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), operandMessage));
57
+ }
58
+ // the operands are always checked, for their own errors and references
59
+ const sourceTypes = [];
52
60
  for (const t of sources) {
53
61
  sourceTypes.push(source_1.Source.runSyntax(t, input));
54
62
  }
@@ -58,14 +66,7 @@ class Compare {
58
66
  for (const t of node.findDirectExpressions(Expressions.MethodCallChain)) {
59
67
  method_call_chain_1.MethodCallChain.runSyntax(t, input);
60
68
  }
61
- const initialMessage = this.checkInitialOperand(node, input);
62
- if (initialMessage !== undefined) {
63
- input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), initialMessage));
64
- return;
65
- }
66
- const predicateMessage = this.checkPredicateOperand(sources, input);
67
- if (predicateMessage !== undefined) {
68
- input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), predicateMessage));
69
+ if (operandMessage !== undefined) {
69
70
  return;
70
71
  }
71
72
  const typeUtils = new _type_utils_1.TypeUtils(input.scope);
@@ -121,35 +122,20 @@ class Compare {
121
122
  if (input.scope.getOpenABAP()) {
122
123
  return undefined;
123
124
  }
125
+ let message = undefined;
124
126
  for (const source of sources) {
125
127
  const name = this.builtinCallName(source, input);
126
128
  if (_builtin_1.BuiltIn.isPredicate(name) === true) {
127
- return `Predicate function "${name}" cannot be the operand of a comparison`;
129
+ source_1.Source.predicateReported(source);
130
+ message = message !== null && message !== void 0 ? message : `Predicate function "${name}" cannot be the operand of a comparison`;
128
131
  }
129
132
  }
130
- return undefined;
133
+ return message;
131
134
  }
132
135
  // the name of the built-in function when the source is exactly one call of it, not hidden by a method of the same name
133
136
  static builtinCallName(source, input) {
134
- var _a;
135
- const chain = source === null || source === void 0 ? void 0 : source.getChildren();
136
- if ((chain === null || chain === void 0 ? void 0 : chain.length) !== 1 || !(chain[0] instanceof nodes_1.ExpressionNode) || !(chain[0].get() instanceof Expressions.MethodCallChain)) {
137
- return undefined;
138
- }
139
- const calls = chain[0].getChildren();
140
- if (calls.length !== 1 || !(calls[0] instanceof nodes_1.ExpressionNode) || !(calls[0].get() instanceof Expressions.MethodCall)) {
141
- return undefined;
142
- }
143
- const name = (_a = calls[0].findDirectExpression(Expressions.MethodName)) === null || _a === void 0 ? void 0 : _a.concatTokens();
144
- if (name === undefined || _builtin_1.BuiltIn.searchBuiltin(name) === undefined) {
145
- return undefined;
146
- }
147
- // a method of the same name hides the built-in function
148
- const enclosing = input.scope.findClassDefinition(input.scope.getEnclosingClassName());
149
- if (enclosing !== undefined && new _object_oriented_1.ObjectOriented(input.scope).searchMethodName(enclosing, name).method !== undefined) {
150
- return undefined;
151
- }
152
- return name;
137
+ const call = _builtin_call_1.BuiltInCall.fromSource(source, input);
138
+ return call === undefined ? undefined : _builtin_call_1.BuiltInCall.callName(call);
153
139
  }
154
140
  }
155
141
  exports.Compare = Compare;
@@ -35,15 +35,22 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.CondBody = void 0;
37
37
  const Expressions = __importStar(require("../../2_statements/expressions"));
38
+ const _object_oriented_1 = require("../_object_oriented");
38
39
  const source_1 = require("./source");
39
40
  const let_1 = require("./let");
40
41
  const cond_1 = require("./cond");
41
42
  const _raise_message_1 = require("../_raise_message");
43
+ const _syntax_input_1 = require("../_syntax_input");
42
44
  class CondBody {
43
45
  static runSyntax(node, input, targetType) {
44
46
  if (node === undefined) {
45
47
  return undefined;
46
48
  }
49
+ const throwNode = node.findDirectExpression(Expressions.Throw);
50
+ const throwMessage = throwNode ? new _object_oriented_1.ObjectOriented(input.scope).checkClassBasedException() : undefined;
51
+ if (throwNode && throwMessage) {
52
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, throwNode.getFirstToken(), throwMessage));
53
+ }
47
54
  let scoped = false;
48
55
  const l = node.findDirectExpression(Expressions.Let);
49
56
  if (l) {
@@ -54,6 +54,7 @@ const conv_body_1 = require("./conv_body");
54
54
  const filter_body_1 = require("./filter_body");
55
55
  const corresponding_body_1 = require("./corresponding_body");
56
56
  const _builtin_1 = require("../_builtin");
57
+ const _builtin_call_1 = require("../_builtin_call");
57
58
  const attribute_chain_1 = require("./attribute_chain");
58
59
  const dereference_1 = require("./dereference");
59
60
  const cast_1 = require("./cast");
@@ -73,6 +74,10 @@ const version_1 = require("../../../version");
73
74
  */
74
75
  // TODO: refactor all these method parameters to objects, this is getting messy
75
76
  class Source {
77
+ // the predicate function in this source is already reported by the caller, Source only checks its arguments
78
+ static predicateReported(source) {
79
+ this.logicalArguments.add(source);
80
+ }
76
81
  static runSyntax(node, input, targetType, writeReference = false, allowGenericDeference = false, readReference = true) {
77
82
  var _a, _b;
78
83
  if (node === undefined) {
@@ -283,6 +288,14 @@ class Source {
283
288
  if (first instanceof nodes_1.ExpressionNode) {
284
289
  const get = first.get();
285
290
  if (get instanceof Expressions.MethodCallChain) {
291
+ const predicate = this.predicateCall(node, first, input);
292
+ if (predicate !== undefined) {
293
+ const message = `Predicate function "${predicate}" can only be used in a logical expression`;
294
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, first.getFirstToken(), message));
295
+ // the arguments are still checked, for their own errors and references
296
+ method_call_chain_1.MethodCallChain.runSyntax(first, input, targetType);
297
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
298
+ }
286
299
  const found = method_call_chain_1.MethodCallChain.runSyntax(first, input, targetType);
287
300
  context = arithmetic === true ? this.infer(context, found, true) : found;
288
301
  if (context === undefined) {
@@ -535,6 +548,36 @@ class Source {
535
548
  }
536
549
  return targetType;
537
550
  }
551
+ // a predicate function, line_exists( ) or contains( ), is a logical expression and not a value,
552
+ // a system reports it as an unknown method in any operand position other than the argument of boolc( ) or xsdbool( ),
553
+ // which parse as method calls in releases before xsdbool( ) was added, or the bool parameter of boolx( )
554
+ static predicateCall(source, chain, input) {
555
+ var _a, _b;
556
+ if (input.scope.getOpenABAP()) {
557
+ return undefined;
558
+ }
559
+ const call = _builtin_call_1.BuiltInCall.fromChain(chain, input);
560
+ const name = call === undefined ? undefined : _builtin_call_1.BuiltInCall.callName(call);
561
+ const upper = name === null || name === void 0 ? void 0 : name.toUpperCase();
562
+ const param = call === null || call === void 0 ? void 0 : call.findDirectExpression(Expressions.MethodCallParam);
563
+ if (upper === "BOOLC" || upper === "XSDBOOL") {
564
+ const argument = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.Source);
565
+ if (argument !== undefined) {
566
+ this.logicalArguments.add(argument);
567
+ }
568
+ return undefined;
569
+ }
570
+ else if (upper === "BOOLX") {
571
+ for (const p of ((_a = param === null || param === void 0 ? void 0 : param.findDirectExpression(Expressions.ParameterListS)) === null || _a === void 0 ? void 0 : _a.findDirectExpressions(Expressions.ParameterS)) || []) {
572
+ const argument = p.findDirectExpression(Expressions.Source);
573
+ if (((_b = p.findDirectExpression(Expressions.ParameterName)) === null || _b === void 0 ? void 0 : _b.concatTokens().toUpperCase()) === "BOOL" && argument !== undefined) {
574
+ this.logicalArguments.add(argument);
575
+ }
576
+ }
577
+ return undefined;
578
+ }
579
+ return _builtin_1.BuiltIn.isPredicate(name) === true && this.logicalArguments.has(source) === false ? name : undefined;
580
+ }
538
581
  // "NEW ty( )->*" is a syntax error, also in releases where a method call can be dereferenced
539
582
  static isNewObjectDereference(node, deref) {
540
583
  var _a;
@@ -547,4 +590,7 @@ class Source {
547
590
  }
548
591
  }
549
592
  exports.Source = Source;
593
+ // arguments of boolc( ), xsdbool( ) and the bool parameter of boolx( ) parsed as method calls, where a predicate function is allowed,
594
+ // and operands where the caller has already reported the predicate function in more specific terms
595
+ Source.logicalArguments = new WeakSet();
550
596
  //# sourceMappingURL=source.js.map
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SwitchBody = void 0;
37
37
  const Expressions = __importStar(require("../../2_statements/expressions"));
38
+ const _object_oriented_1 = require("../_object_oriented");
38
39
  const source_1 = require("./source");
39
40
  const _raise_message_1 = require("../_raise_message");
40
41
  const _syntax_input_1 = require("../_syntax_input");
@@ -44,6 +45,11 @@ class SwitchBody {
44
45
  if (node === undefined) {
45
46
  return;
46
47
  }
48
+ const throwNode = node.findDirectExpression(Expressions.Throw);
49
+ const throwMessage = throwNode ? new _object_oriented_1.ObjectOriented(input.scope).checkClassBasedException() : undefined;
50
+ if (throwNode && throwMessage) {
51
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, throwNode.getFirstToken(), throwMessage));
52
+ }
47
53
  for (const t of node.findDirectExpressions(Expressions.Throw)) {
48
54
  _raise_message_1.RaiseMessage.checkThrow(t, input);
49
55
  }
@@ -42,6 +42,7 @@ const target_1 = require("../expressions/target");
42
42
  const message_source_1 = require("../expressions/message_source");
43
43
  const _syntax_input_1 = require("../_syntax_input");
44
44
  const _object_oriented_1 = require("../_object_oriented");
45
+ const _builtin_call_1 = require("../_builtin_call");
45
46
  class Message {
46
47
  runSyntax(node, input) {
47
48
  const exceptionName = node.findDirectExpression(Expressions.ExceptionName);
@@ -60,7 +61,16 @@ class Message {
60
61
  }
61
62
  for (const mss of node.findDirectExpressions(Expressions.MessageSourceSource)) {
62
63
  for (const s of mss.findDirectExpressions(Expressions.Source)) {
64
+ const issueCount = input.issues.length;
63
65
  source_1.Source.runSyntax(s, input);
66
+ // "Arithmetic calculation not permitted here" on a system, whatever the argument
67
+ const call = issueCount === input.issues.length && input.scope.getOpenABAP() === false
68
+ ? _builtin_call_1.BuiltInCall.fromSource(s, input) : undefined;
69
+ if (call !== undefined && _builtin_call_1.BuiltInCall.isNumeric(call)) {
70
+ const message = `Numeric function "${_builtin_call_1.BuiltInCall.callName(call)}" cannot be used in MESSAGE WITH`;
71
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
72
+ return;
73
+ }
64
74
  }
65
75
  for (const s of mss.findDirectExpressions(Expressions.SimpleSource3)) {
66
76
  source_1.Source.runSyntax(s, input);
@@ -57,6 +57,11 @@ class Raise {
57
57
  input.issues.push((0, _syntax_input_1.syntaxIssue)(input, exceptionName.getFirstToken(), classicMessage));
58
58
  return;
59
59
  }
60
+ const classBasedMessage = exceptionName === undefined && node.findDirectTokenByText("EXCEPTION")
61
+ ? helper.checkClassBasedException() : undefined;
62
+ if (classBasedMessage) {
63
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), classBasedMessage));
64
+ }
60
65
  const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
61
66
  const className = classTok === null || classTok === void 0 ? void 0 : classTok.getStr();
62
67
  if (classTok && className) {
@@ -42,6 +42,7 @@ const _type_utils_1 = require("../_type_utils");
42
42
  const field_chain_1 = require("../expressions/field_chain");
43
43
  const _reference_1 = require("../_reference");
44
44
  const _syntax_input_1 = require("../_syntax_input");
45
+ const _builtin_call_1 = require("../_builtin_call");
45
46
  class Write {
46
47
  runSyntax(node, input) {
47
48
  // todo, more
@@ -51,7 +52,16 @@ class Write {
51
52
  second = node.getChildren()[2];
52
53
  }
53
54
  for (const s of node.findDirectExpressions(Expressions.Source)) {
55
+ const issueCount = input.issues.length;
54
56
  const type = source_1.Source.runSyntax(s, input);
57
+ // "Arithmetic calculation not permitted here" on a system, while abs( x ) or lines( itab ) is fine
58
+ const call = s === second && issueCount === input.issues.length && input.scope.getOpenABAP() === false
59
+ ? _builtin_call_1.BuiltInCall.fromSource(s, input) : undefined;
60
+ if (call !== undefined && _builtin_call_1.BuiltInCall.isNumeric(call) && _builtin_call_1.BuiltInCall.hasDataObjectArgument(call) === false) {
61
+ const message = `Numeric function "${_builtin_call_1.BuiltInCall.callName(call)}" in WRITE takes only a single data object as argument`;
62
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, s.getFirstToken(), message));
63
+ return;
64
+ }
55
65
  if (s === second
56
66
  && new _type_utils_1.TypeUtils(input.scope).isCharLike(type) === false
57
67
  && new _type_utils_1.TypeUtils(input.scope).isHexLike(type) === false) {
@@ -78,7 +78,7 @@ class Registry {
78
78
  }
79
79
  static abaplintVersion() {
80
80
  // magic, see build script "version.js"
81
- return "2.120.111";
81
+ return "2.120.112";
82
82
  }
83
83
  getDDICReferences() {
84
84
  return this.ddicReferences;
@@ -40,6 +40,7 @@ const issue_1 = require("../issue");
40
40
  const _basic_rule_config_1 = require("./_basic_rule_config");
41
41
  const _abap_rule_1 = require("./_abap_rule");
42
42
  const _irule_1 = require("./_irule");
43
+ const _statement_1 = require("../abap/2_statements/statements/_statement");
43
44
  class LoopTargetMisuseConf extends _basic_rule_config_1.BasicRuleConfig {
44
45
  constructor() {
45
46
  super(...arguments);
@@ -48,6 +49,9 @@ class LoopTargetMisuseConf extends _basic_rule_config_1.BasicRuleConfig {
48
49
  /** Report LOOP AT ... INTO <fs> and READ TABLE ... INTO <fs> when the local field symbol is only bound by ASSIGNING,
49
50
  * so the statement overwrites a table row */
50
51
  this.intoFieldSymbol = true;
52
+ /** Report a field symbol of LOOP AT ... ASSIGNING used after ENDLOOP, and a field symbol of READ TABLE ... ASSIGNING
53
+ * used after the check of sy-subrc, outside the branch that found the row */
54
+ this.usedAfterLoop = true;
51
55
  }
52
56
  }
53
57
  exports.LoopTargetMisuseConf = LoopTargetMisuseConf;
@@ -73,7 +77,21 @@ Option intoFieldSymbol: LOOP AT ... INTO <fs> or READ TABLE ... INTO <fs>. INTO
73
77
  into the data object the field symbol points to. When <fs> was bound by ASSIGNING, that data
74
78
  object is a row of a table, and the statement overwrites it. ASSIGNING was meant.
75
79
  Reported only for a field symbol declared in the method, form or function module, and only when
76
- no ASSIGN and no STRUCTURE ... DEFAULT binds it there, so it can only point to a table row.`,
80
+ no ASSIGN and no STRUCTURE ... DEFAULT binds it there, so it can only point to a table row.
81
+
82
+ Option usedAfterLoop: a field symbol of LOOP AT ... ASSIGNING used after ENDLOOP. It points to
83
+ the last row the loop processed. When the loop processed no row, it is not assigned, and the use
84
+ raises GETWA_NOT_ASSIGNED, or it still points to what it was bound to before the loop.
85
+ Also a field symbol of READ TABLE ... ASSIGNING used after sy-subrc was checked, outside the
86
+ branch of that check. When the READ fails, the field symbol keeps its previous binding.
87
+ Reported at the first such use in the method, form or function module.
88
+ Not reported: a use inside IF, ELSEIF, CASE or WHILE whose condition reads sy-subrc, the table of
89
+ the loop or a variable the loop body sets (a flag), a use after such a check that leaves with
90
+ RETURN, EXIT, CONTINUE, CHECK, RAISE or MESSAGE or that does not use the field symbol, a use after
91
+ CHECK or ASSERT of such a condition, and any use after IS ASSIGNED, UNASSIGN or another binding of
92
+ the field symbol, or after a macro call. Work areas of INTO are not checked, they keep a value.
93
+ A READ TABLE whose sy-subrc is not checked at all is left to check_subrc, a LOOP inside a LOOP
94
+ with the same field symbol to the option nestedLoop.`,
77
95
  tags: [_irule_1.RuleTag.SingleFile],
78
96
  badExample: `LOOP AT lt_header INTO ls_row.
79
97
  LOOP AT lt_items INTO ls_row WHERE parent = ls_row-id.
@@ -85,7 +103,12 @@ ENDLOOP.
85
103
 
86
104
  LOOP AT lt_a ASSIGNING <ls_a>.
87
105
  ENDLOOP.
88
- READ TABLE lt_a INTO <ls_a> INDEX 1.`,
106
+ READ TABLE lt_a INTO <ls_a> INDEX 1.
107
+
108
+ LOOP AT lt_a ASSIGNING <ls_a> WHERE id = lv_id.
109
+ EXIT.
110
+ ENDLOOP.
111
+ <ls_a>-flag = abap_true.`,
89
112
  goodExample: `LOOP AT lt_header INTO ls_row.
90
113
  LOOP AT lt_items INTO ls_item WHERE parent = ls_row-id.
91
114
  lv_sum = lv_sum + ls_item-amount.
@@ -96,7 +119,14 @@ ENDLOOP.
96
119
 
97
120
  LOOP AT lt_a ASSIGNING <ls_a>.
98
121
  ENDLOOP.
99
- READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
122
+ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.
123
+
124
+ LOOP AT lt_a ASSIGNING <ls_a> WHERE id = lv_id.
125
+ EXIT.
126
+ ENDLOOP.
127
+ IF sy-subrc = 0.
128
+ <ls_a>-flag = abap_true.
129
+ ENDIF.`,
100
130
  };
101
131
  }
102
132
  getConfig() {
@@ -114,6 +144,14 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
114
144
  if (this.conf.intoFieldSymbol !== false) {
115
145
  issues.push(...this.checkIntoFieldSymbol(file, statements));
116
146
  }
147
+ if (this.conf.usedAfterLoop !== false) {
148
+ for (const issue of this.checkUsedAfterLoop(file, statements)) {
149
+ // a READ TABLE ... INTO <fs> after the loop is already reported by the option intoFieldSymbol
150
+ if (issues.some(i => i.getStart().equals(issue.getStart())) === false) {
151
+ issues.push(issue);
152
+ }
153
+ }
154
+ }
117
155
  return issues;
118
156
  }
119
157
  ////////////////
@@ -170,7 +208,7 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
170
208
  let depth = 0;
171
209
  for (let i = index + 1; i < statements.length && this.isBlockBoundary(statements[i]) === false; i++) {
172
210
  const s = statements[i].get();
173
- if (s instanceof Statements.Loop) {
211
+ if (s instanceof Statements.Loop || s instanceof Statements.LoopAtScreen || s instanceof Statements.LoopExtract) {
174
212
  depth++;
175
213
  }
176
214
  else if (s instanceof Statements.EndLoop) {
@@ -279,6 +317,232 @@ READ TABLE lt_a ASSIGNING <ls_a> INDEX 1.`,
279
317
  var _a;
280
318
  return (_a = fsTarget.findFirstExpression(Expressions.FieldSymbol)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase();
281
319
  }
320
+ checkUsedAfterLoop(file, statements) {
321
+ var _a;
322
+ const issues = [];
323
+ // the field symbols of the open LOOPs, undefined for a LOOP without field symbol
324
+ let open = [];
325
+ for (let i = 0; i < statements.length; i++) {
326
+ const statement = statements[i];
327
+ const s = statement.get();
328
+ if (this.isBlockBoundary(statement)) {
329
+ open = [];
330
+ continue;
331
+ }
332
+ else if (s instanceof Statements.EndLoop) {
333
+ open.pop();
334
+ continue;
335
+ }
336
+ let use = undefined;
337
+ let name = undefined;
338
+ let what = "";
339
+ if (s instanceof Statements.Loop) {
340
+ const node = this.loopTarget(statement);
341
+ name = (node === null || node === void 0 ? void 0 : node.get()) instanceof Expressions.FSTarget ? this.targetName(node) : undefined;
342
+ const end = this.findEndLoop(statements, i);
343
+ // a LOOP inside a LOOP with the same field symbol is left to the option nestedLoop
344
+ if (name !== undefined && end !== undefined && open.includes(name) === false) {
345
+ const guards = this.loopGuards(statements, i, end, name);
346
+ use = this.findUncheckedUse(statements, end + 1, name, guards, false);
347
+ what = `after ENDLOOP, it points to the last row, or is not assigned when the loop processed no row`;
348
+ }
349
+ open.push(name);
350
+ }
351
+ else if (s instanceof Statements.LoopAtScreen || s instanceof Statements.LoopExtract) {
352
+ open.push(undefined);
353
+ }
354
+ else if (s instanceof Statements.ReadTable) {
355
+ const fs = (_a = statement.findDirectExpression(Expressions.ReadTableTarget)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.FSTarget);
356
+ name = fs ? this.targetName(fs) : undefined;
357
+ if (name !== undefined) {
358
+ use = this.findUncheckedUse(statements, i + 1, name, new Set(), true);
359
+ what = `outside the check of sy-subrc, when the READ TABLE fails it is not assigned or points to an earlier row`;
360
+ }
361
+ }
362
+ if (use !== undefined && name !== undefined) {
363
+ const token = statements[use].getTokens().find(t => t.getStr().toUpperCase() === name);
364
+ const message = `${token === null || token === void 0 ? void 0 : token.getStr()} is used ${what}`;
365
+ issues.push(issue_1.Issue.atStatement(file, statements[use], message, this.getMetadata().key, this.conf.severity));
366
+ }
367
+ }
368
+ return issues;
369
+ }
370
+ /** upper case names of the variables whose check counts as a check that the LOOP processed a row:
371
+ * the table and the variables the loop body writes */
372
+ loopGuards(statements, loop, end, name) {
373
+ var _a;
374
+ const guards = new Set();
375
+ const first = (_a = statements[loop].findDirectExpression(Expressions.LoopSource)) === null || _a === void 0 ? void 0 : _a.getFirstToken().getStr().toUpperCase();
376
+ if (first !== undefined) {
377
+ guards.add(first);
378
+ }
379
+ for (let i = loop + 1; i < end; i++) {
380
+ for (const target of statements[i].findAllExpressions(Expressions.Target)) {
381
+ guards.add(this.firstName(target));
382
+ }
383
+ }
384
+ guards.delete(name);
385
+ return guards;
386
+ }
387
+ /** upper case name of the variable a Target writes, also declared inline */
388
+ firstName(target) {
389
+ const inline = target.findFirstExpression(Expressions.TargetField);
390
+ return (inline ? inline.getFirstToken() : target.getFirstToken()).getStr().toUpperCase();
391
+ }
392
+ /** index of the first statement from the index on that uses the field symbol without a check before it,
393
+ * looking until the end of the method, form or function module or until the field symbol is bound again.
394
+ * With checkFirst, only a use after a check is returned, an unchecked READ TABLE is left to check_subrc */
395
+ findUncheckedUse(statements, from, name, guards, checkFirst) {
396
+ const frames = [];
397
+ let checked = false;
398
+ let sawCheck = false;
399
+ for (let i = from; i < statements.length && this.isBlockBoundary(statements[i]) === false; i++) {
400
+ const statement = statements[i];
401
+ const s = statement.get();
402
+ if (s instanceof _statement_1.MacroCall || s instanceof _statement_1.Unknown || this.bindsOrTests(statement, name)) {
403
+ return undefined;
404
+ }
405
+ const isCondition = s instanceof Statements.If || s instanceof Statements.ElseIf || s instanceof Statements.Case
406
+ || s instanceof Statements.When || s instanceof Statements.While
407
+ || s instanceof Statements.Check || s instanceof Statements.Assert;
408
+ const guard = isCondition && this.isGuard(statement, guards);
409
+ sawCheck = sawCheck || guard;
410
+ if ((s instanceof Statements.Check || s instanceof Statements.Assert) && guard) {
411
+ checked = true;
412
+ }
413
+ if (s instanceof Statements.FieldSymbol === false && this.mentions(statement, name)) {
414
+ if (guard || checked || frames.some(f => f.guard)) {
415
+ frames.forEach(f => f.uses = true);
416
+ }
417
+ else if (checkFirst === false || sawCheck === true) {
418
+ return i;
419
+ }
420
+ }
421
+ if (guard || frames.some(f => f.guard)) {
422
+ // a flag set where the check holds, like lv_found = abap_true, checks it as well
423
+ for (const target of statement.findAllExpressions(Expressions.Target)) {
424
+ guards.add(this.firstName(target));
425
+ }
426
+ guards.delete(name);
427
+ }
428
+ if (this.leaves(statement)) {
429
+ frames.forEach(f => f.leaves = true);
430
+ }
431
+ if (this.opensBlock(statement)) {
432
+ frames.push({ guard, uses: false, leaves: false });
433
+ }
434
+ else if (this.isBranch(statement)) {
435
+ if (frames.length === 0) {
436
+ // another branch of a block around the binding, it does not run after it
437
+ return undefined;
438
+ }
439
+ frames[frames.length - 1].guard = frames[frames.length - 1].guard || guard;
440
+ }
441
+ else if (this.closesBlock(statement)) {
442
+ const frame = frames.pop();
443
+ // IF sy-subrc <> 0. RETURN. ENDIF., or a check that sets a flag
444
+ if (frame && frame.guard && (frame.leaves || frame.uses === false)) {
445
+ checked = true;
446
+ }
447
+ }
448
+ }
449
+ return undefined;
450
+ }
451
+ /** true when the statement binds the field symbol again, unassigns it, or checks IS ASSIGNED */
452
+ bindsOrTests(statement, name) {
453
+ if (statement.get() instanceof Statements.Unassign && this.mentions(statement, name)) {
454
+ return true;
455
+ }
456
+ for (const fsTarget of statement.findAllExpressions(Expressions.FSTarget)) {
457
+ if (this.targetName(fsTarget) === name) {
458
+ return true;
459
+ }
460
+ }
461
+ const tokens = statement.getTokens().map(t => t.getStr().toUpperCase());
462
+ for (let i = 0; i < tokens.length - 2; i++) {
463
+ if (tokens[i] === name && tokens[i + 1] === "IS"
464
+ && (tokens[i + 2] === "ASSIGNED" || (tokens[i + 2] === "NOT" && tokens[i + 3] === "ASSIGNED"))) {
465
+ return true;
466
+ }
467
+ }
468
+ return false;
469
+ }
470
+ /** true when the condition reads sy-subrc or one of the variables */
471
+ isGuard(statement, guards) {
472
+ var _a, _b;
473
+ const tokens = statement.getTokens();
474
+ for (let i = 0; i < tokens.length; i++) {
475
+ const str = tokens[i].getStr().toUpperCase();
476
+ const previous = i > 0 ? tokens[i - 1].getStr() : "";
477
+ if (["-", "->", "=>", "~"].includes(previous)) {
478
+ continue;
479
+ }
480
+ if ((str === "SY" && ((_a = tokens[i + 1]) === null || _a === void 0 ? void 0 : _a.getStr()) === "-" && ((_b = tokens[i + 2]) === null || _b === void 0 ? void 0 : _b.getStr().toUpperCase()) === "SUBRC")
481
+ || guards.has(str)) {
482
+ return true;
483
+ }
484
+ }
485
+ return false;
486
+ }
487
+ mentions(statement, name) {
488
+ return statement.getTokens().some(t => t.getStr().toUpperCase() === name);
489
+ }
490
+ /** true for a statement that can leave the current block, a call of a method named like RAISE counts */
491
+ leaves(statement) {
492
+ const s = statement.get();
493
+ return s instanceof Statements.Return
494
+ || s instanceof Statements.Exit
495
+ || s instanceof Statements.Continue
496
+ || s instanceof Statements.Check
497
+ || s instanceof Statements.Raise
498
+ || s instanceof Statements.Leave
499
+ || s instanceof Statements.Message
500
+ || s instanceof Statements.Assert
501
+ || (s instanceof Statements.Call && statement.getTokens().some(t => /raise/i.test(t.getStr())));
502
+ }
503
+ opensBlock(statement) {
504
+ const s = statement.get();
505
+ return s instanceof Statements.If
506
+ || s instanceof Statements.Case
507
+ || s instanceof Statements.CaseType
508
+ || s instanceof Statements.Loop
509
+ || s instanceof Statements.LoopAtScreen
510
+ || s instanceof Statements.LoopExtract
511
+ || s instanceof Statements.Do
512
+ || s instanceof Statements.While
513
+ || s instanceof Statements.Try
514
+ || s instanceof Statements.SelectLoop
515
+ || s instanceof Statements.At
516
+ || s instanceof Statements.AtFirst
517
+ || s instanceof Statements.AtLast
518
+ || s instanceof Statements.OnChange
519
+ || s instanceof Statements.Provide
520
+ || s instanceof Statements.CatchSystemExceptions;
521
+ }
522
+ isBranch(statement) {
523
+ const s = statement.get();
524
+ return s instanceof Statements.ElseIf
525
+ || s instanceof Statements.Else
526
+ || s instanceof Statements.When
527
+ || s instanceof Statements.WhenOthers
528
+ || s instanceof Statements.WhenType
529
+ || s instanceof Statements.Catch
530
+ || s instanceof Statements.Cleanup;
531
+ }
532
+ closesBlock(statement) {
533
+ const s = statement.get();
534
+ return s instanceof Statements.EndIf
535
+ || s instanceof Statements.EndCase
536
+ || s instanceof Statements.EndLoop
537
+ || s instanceof Statements.EndDo
538
+ || s instanceof Statements.EndWhile
539
+ || s instanceof Statements.EndTry
540
+ || s instanceof Statements.EndSelect
541
+ || s instanceof Statements.EndAt
542
+ || s instanceof Statements.EndOn
543
+ || s instanceof Statements.EndProvide
544
+ || s instanceof Statements.EndCatch;
545
+ }
282
546
  isBlockBoundary(statement) {
283
547
  return this.startsBlock(statement) || this.endsBlock(statement);
284
548
  }
@@ -109,8 +109,16 @@ text = text.`,
109
109
  if (structure === undefined) {
110
110
  continue;
111
111
  }
112
+ const sources = structure.findAllExpressionsRecursive(Expressions.Source);
113
+ // Sources that are an operand of an enclosing Source, e.g. "2 * CONV i( a + b )" or "- CONV i( a + b )"
114
+ const operands = new Set();
115
+ for (const source of sources) {
116
+ if (source.getChildren().length > 1) {
117
+ source.findDirectExpressions(Expressions.Source).forEach(operand => operands.add(operand));
118
+ }
119
+ }
112
120
  // recursive, a CONV can be the argument of a built-in function, which is itself a Source
113
- for (const source of structure.findAllExpressionsRecursive(Expressions.Source)) {
121
+ for (const source of sources) {
114
122
  if (source.getFirstToken().getStr().toUpperCase() !== "CONV") {
115
123
  continue;
116
124
  }
@@ -143,8 +151,12 @@ text = text.`,
143
151
  if (closingParen === undefined) {
144
152
  continue;
145
153
  }
146
- const preserveParentheses = bodySource.findDirectExpression(Expressions.ArithOperator) !== undefined
147
- || bodySource.findDirectTokenByText("&&") !== undefined;
154
+ // parentheses are only needed when the CONV takes part in a surrounding operation,
155
+ // "CONV type ( body )" alone has 5 children, more means a trailing operator
156
+ const partOfOperation = source.getChildren().length !== 5 || operands.has(source);
157
+ const preserveParentheses = partOfOperation
158
+ && (bodySource.findDirectExpression(Expressions.ArithOperator) !== undefined
159
+ || bodySource.findDirectTokenByText("&&") !== undefined);
148
160
  // Apply the later edit first so the original positions remain valid when
149
161
  // both parts of the CONV wrapper are changed on the same line.
150
162
  const fix = edit_helper_1.EditHelper.merge(edit_helper_1.EditHelper.replaceRange(file, bodySource.getLastToken().getEnd(), closingParen.getEnd(), preserveParentheses ? ")" : ""), edit_helper_1.EditHelper.replaceRange(file, source.getFirstToken().getStart(), bodySource.getFirstToken().getStart(), preserveParentheses ? "(" : ""));
@@ -41,6 +41,15 @@ const Statements = __importStar(require("../abap/2_statements/statements"));
41
41
  const Expressions = __importStar(require("../abap/2_statements/expressions"));
42
42
  const _irule_1 = require("./_irule");
43
43
  class RFCErrorHandlingConf extends _basic_rule_config_1.BasicRuleConfig {
44
+ constructor() {
45
+ super(...arguments);
46
+ /** Also check CALL FUNCTION ... STARTING NEW TASK without DESTINATION, an asynchronous RFC to the destination NONE */
47
+ this.startingNewTask = true;
48
+ /** Report error_message in the EXCEPTIONS of an RFC call, it is ignored in RFC */
49
+ this.errorMessage = true;
50
+ /** Report SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE, the error text is lost */
51
+ this.requireMessage = false;
52
+ }
44
53
  }
45
54
  exports.RFCErrorHandlingConf = RFCErrorHandlingConf;
46
55
  class RFCErrorHandling extends _abap_rule_1.ABAPRule {
@@ -56,11 +65,35 @@ class RFCErrorHandling extends _abap_rule_1.ABAPRule {
56
65
  shortDescription: `Checks that exceptions 'system_failure' and 'communication_failure' are handled in RFC calls`,
57
66
  extendedInformation: `RESOURCE_FAILURE is also required for asynchronous calls with DESTINATION IN GROUP.
58
67
 
59
- https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exception.html`,
68
+ Checked are CALL FUNCTION ... DESTINATION and, with startingNewTask, CALL FUNCTION ... STARTING NEW TASK
69
+ without DESTINATION, which is an asynchronous RFC to the destination NONE.
70
+ CALL FUNCTION ... IN BACKGROUND TASK is not checked, it cannot have EXCEPTIONS.
71
+
72
+ errorMessage: reports error_message in the EXCEPTIONS of an RFC call. It is ignored in RFC, a message of
73
+ type A, E or X ends the called function module and raises SYSTEM_FAILURE, use system_failure = n MESSAGE msg
74
+ to get the message text. Exception: with a DESTINATION that is blank at runtime, the call is local.
75
+
76
+ requireMessage: reports SYSTEM_FAILURE and COMMUNICATION_FAILURE without the addition MESSAGE.
77
+
78
+ https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exception.html
79
+ https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abapcall_function_destination_para.html`,
60
80
  badExample: `CALL FUNCTION 'ZRFC'
61
- DESTINATION lv_rfc.`,
81
+ DESTINATION lv_rfc.
82
+
83
+ CALL FUNCTION 'ZRFC'
84
+ STARTING NEW TASK 'TASK'
85
+ EXCEPTIONS
86
+ error_message = 1
87
+ OTHERS = 2.`,
62
88
  goodExample: `CALL FUNCTION 'ZRFC'
63
89
  DESTINATION lv_rfc
90
+ EXCEPTIONS
91
+ system_failure = 1 MESSAGE msg
92
+ communication_failure = 2 MESSAGE msg
93
+ OTHERS = 3.
94
+
95
+ CALL FUNCTION 'ZRFC'
96
+ STARTING NEW TASK 'TASK'
64
97
  EXCEPTIONS
65
98
  system_failure = 1 MESSAGE msg
66
99
  communication_failure = 2 MESSAGE msg
@@ -85,28 +118,45 @@ https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abenrfc_exceptio
85
118
  continue;
86
119
  }
87
120
  const destination = stat.findFirstExpression(Expressions.Destination);
88
- if (destination === undefined) {
121
+ const starting = stat.findDirectTokenByText("STARTING") !== undefined;
122
+ if (destination === undefined && (starting === false || this.conf.startingNewTask === false)) {
123
+ continue;
124
+ }
125
+ if (stat.findDirectTokenByText("BACKGROUND") !== undefined) {
126
+ // transactional RFC, it has no EXCEPTIONS
89
127
  continue;
90
128
  }
91
- const requireResourceFailure = stat.findDirectTokenByText("STARTING") !== undefined
92
- && destination.findDirectTokenByText("GROUP") !== undefined;
129
+ const requireResourceFailure = starting === true
130
+ && (destination === null || destination === void 0 ? void 0 : destination.findDirectTokenByText("GROUP")) !== undefined;
93
131
  const list = stat.findFirstExpression(Expressions.ParameterListExceptions);
94
132
  if (list === undefined) {
95
133
  const issue = issue_1.Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
96
134
  output.push(issue);
97
135
  continue;
98
136
  }
99
- const parameters = list.findAllExpressions(Expressions.ParameterName);
100
- const names = [];
101
- for (const par of parameters) {
102
- names.push(par.getFirstToken().getStr().toUpperCase());
137
+ const exceptions = new Map();
138
+ for (const exception of list.findDirectExpressions(Expressions.ParameterException)) {
139
+ exceptions.set(exception.getFirstToken().getStr().toUpperCase(), exception);
103
140
  }
104
- if (names.indexOf("SYSTEM_FAILURE") < 0
105
- || names.indexOf("COMMUNICATION_FAILURE") < 0
106
- || (requireResourceFailure && names.indexOf("RESOURCE_FAILURE") < 0)) {
141
+ if (exceptions.has("SYSTEM_FAILURE") === false
142
+ || exceptions.has("COMMUNICATION_FAILURE") === false
143
+ || (requireResourceFailure && exceptions.has("RESOURCE_FAILURE") === false)) {
107
144
  const issue = issue_1.Issue.atToken(file, token, this.getMessage(requireResourceFailure), this.getMetadata().key, this.conf.severity);
108
145
  output.push(issue);
109
- continue;
146
+ }
147
+ const errorMessage = exceptions.get("ERROR_MESSAGE");
148
+ if (this.conf.errorMessage !== false && errorMessage !== undefined) {
149
+ const message = "error_message is ignored in RFC, messages of type A, E and X raise SYSTEM_FAILURE, use system_failure = n MESSAGE msg";
150
+ output.push(issue_1.Issue.atToken(file, errorMessage.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
151
+ }
152
+ if (this.conf.requireMessage === true) {
153
+ for (const name of ["SYSTEM_FAILURE", "COMMUNICATION_FAILURE"]) {
154
+ const exception = exceptions.get(name);
155
+ if (exception !== undefined && exception.findDirectTokenByText("MESSAGE") === undefined) {
156
+ const message = `${name} without MESSAGE, the error text is lost, use ${name.toLowerCase()} = n MESSAGE msg`;
157
+ output.push(issue_1.Issue.atToken(file, exception.getFirstToken(), message, this.getMetadata().key, this.conf.severity));
158
+ }
159
+ }
110
160
  }
111
161
  }
112
162
  return output;
@@ -55,6 +55,8 @@ class UnhandledClassicExceptionConf extends _basic_rule_config_1.BasicRuleConfig
55
55
  this.missingExceptions = true;
56
56
  /** missingExceptions: do not report a method call whose arguments are all literals or me, like describe_by_name( 'T100' ) */
57
57
  this.allowLiteralArguments = true;
58
+ /** Report CALL FUNCTION without error_message, the policy "always list error_message", for code that runs outside dialog */
59
+ this.missingErrorMessage = false;
58
60
  }
59
61
  }
60
62
  exports.UnhandledClassicExceptionConf = UnhandledClassicExceptionConf;
@@ -80,6 +82,13 @@ missingExceptions: reports calls without EXCEPTIONS of a method or function modu
80
82
  this includes functional calls, which cannot have EXCEPTIONS.
81
83
  With allowLiteralArguments, a method call whose arguments are all literals or me is not reported.
82
84
 
85
+ missingErrorMessage, off by default: reports every CALL FUNCTION that does not list the predefined exception error_message,
86
+ the policy "always list error_message". Any function module can send a MESSAGE without RAISING, directly or from a
87
+ function module it calls, and OTHERS does not catch it. Outside dialog, in HTTP handlers, RFC and background jobs,
88
+ a message of type E or A ends the processing. Use it together with check_subrc, otherwise error_message turns a
89
+ visible abort into a silent failure. Not reported: DESTINATION, STARTING NEW TASK, IN UPDATE TASK, IN BACKGROUND,
90
+ EXCEPTION-TABLE, and function modules in the registry with class-based exceptions.
91
+
83
92
  Signatures are taken from the registry, including dependencies. Methods and function modules that are not
84
93
  found (void) are only checked by missingOthers.
85
94
 
@@ -140,7 +149,7 @@ cl_abap_typedescr=>describe_by_name(
140
149
  if (nameNode) {
141
150
  const token = nameNode.getFirstToken();
142
151
  const callee = nameNode.get() instanceof Expressions.Dynamic ? undefined : this.findMethod(methods, token);
143
- const issue = this.checkCall(file, token, callee, body === null || body === void 0 ? void 0 : body.findDirectExpression(Expressions.MethodParameters), (body === null || body === void 0 ? void 0 : body.findDirectTokenByText("EXCEPTION-TABLE")) !== undefined, false, this.onlyLiterals(body));
152
+ const issue = this.checkCall(file, token, callee, body === null || body === void 0 ? void 0 : body.findDirectExpression(Expressions.MethodParameters), (body === null || body === void 0 ? void 0 : body.findDirectTokenByText("EXCEPTION")) !== undefined, false, this.onlyLiterals(body));
144
153
  if (issue) {
145
154
  issues.push(issue);
146
155
  }
@@ -162,6 +171,7 @@ cl_abap_typedescr=>describe_by_name(
162
171
  return issues;
163
172
  }
164
173
  checkCallFunction(statement, file) {
174
+ var _a;
165
175
  if (statement.findDirectTokenByText("STARTING")
166
176
  || statement.findDirectTokenByText("UPDATE")
167
177
  || statement.findDirectTokenByText("BACKGROUND")) {
@@ -172,18 +182,35 @@ cl_abap_typedescr=>describe_by_name(
172
182
  return [];
173
183
  }
174
184
  let callee = undefined;
185
+ let classBased = false;
175
186
  if (nameNode.findFirstExpression(Expressions.FieldChain) === undefined) {
176
187
  const name = nameNode.concatTokens().replace(/'/g, "").replace(/`/g, "");
177
188
  const module = this.findFunctionModule(name);
178
189
  if (module) {
190
+ classBased = module.isClassBasedExceptions();
179
191
  callee = {
180
192
  name: module.getName(),
181
- exceptions: module.isClassBasedExceptions() ? [] : module.getExceptions().map(e => e.toUpperCase()),
193
+ exceptions: classBased ? [] : module.getExceptions().map(e => e.toUpperCase()),
182
194
  };
183
195
  }
184
196
  }
185
- const issue = this.checkCall(file, nameNode.getFirstToken(), callee, statement.findDirectExpression(Expressions.FunctionParameters), statement.findDirectTokenByText("EXCEPTION-TABLE") !== undefined, statement.findDirectExpression(Expressions.Destination) !== undefined, false);
186
- return issue ? [issue] : [];
197
+ const issues = [];
198
+ const parameters = statement.findDirectExpression(Expressions.FunctionParameters);
199
+ const exceptionTable = statement.findDirectTokenByText("EXCEPTION") !== undefined;
200
+ const destination = statement.findDirectExpression(Expressions.Destination) !== undefined;
201
+ const issue = this.checkCall(file, nameNode.getFirstToken(), callee, parameters, exceptionTable, destination, false);
202
+ if (issue) {
203
+ issues.push(issue);
204
+ }
205
+ if (this.conf.missingErrorMessage === true && exceptionTable === false && destination === false && classBased === false) {
206
+ const listed = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.findDirectExpression(Expressions.ParameterListExceptions)) === null || _a === void 0 ? void 0 : _a.findDirectExpressions(Expressions.ParameterException).some(e => e.getFirstChild().concatTokens().toUpperCase() === "ERROR_MESSAGE");
207
+ if (listed !== true) {
208
+ const position = (parameters === null || parameters === void 0 ? void 0 : parameters.findDirectTokenByText("EXCEPTIONS")) || nameNode.getFirstToken();
209
+ const message = "No error_message, OTHERS does not catch a message that the function module sends without RAISING";
210
+ issues.push(issue_1.Issue.atToken(file, position, message, this.getMetadata().key, this.conf.severity));
211
+ }
212
+ }
213
+ return issues;
187
214
  }
188
215
  checkCall(file, token, callee, parameters, exceptionTable, destination, onlyLiterals) {
189
216
  if (exceptionTable === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.111",
3
+ "version": "2.120.112",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",