@abaplint/core 2.120.99 → 2.120.101

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.
@@ -0,0 +1,151 @@
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.RaiseMessage = void 0;
37
+ const Expressions = __importStar(require("../2_statements/expressions"));
38
+ const nodes_1 = require("../nodes");
39
+ const _syntax_input_1 = require("./_syntax_input");
40
+ const T100_INTERFACES = new Set(["IF_T100_MESSAGE", "IF_T100_DYN_MSG"]);
41
+ // the root exception classes, they implement IF_MESSAGE and IF_SERIALIZABLE_OBJECT, but not the T100 interfaces
42
+ const ROOT_EXCEPTIONS = new Set(["CX_ROOT", "CX_STATIC_CHECK", "CX_DYNAMIC_CHECK", "CX_NO_CHECK"]);
43
+ /** RAISE EXCEPTION TYPE cx MESSAGE ... and THROW cx( MESSAGE ... ) require the exception class to implement
44
+ * IF_T100_MESSAGE or IF_T100_DYN_MSG, and with RAISE EXCEPTION the constructor parameter TEXTID cannot be
45
+ * passed in addition to MESSAGE, see the ABAP keyword documentation for RAISE EXCEPTION, MESSAGE.
46
+ * The interface check only reports when the full class hierarchy is known, void classes and void interfaces
47
+ * in the hierarchy are skipped, except for the root exception classes. */
48
+ class RaiseMessage {
49
+ static checkRaise(node, input) {
50
+ var _a, _b, _c;
51
+ var _d;
52
+ const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
53
+ if (classTok === undefined || RaiseMessage.hasMessage(node) === false) {
54
+ return;
55
+ }
56
+ for (const p of (_d = (_b = node.findDirectExpression(Expressions.ParameterListS)) === null || _b === void 0 ? void 0 : _b.findDirectExpressions(Expressions.ParameterS)) !== null && _d !== void 0 ? _d : []) {
57
+ const name = (_c = p.findDirectExpression(Expressions.ParameterName)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
58
+ if ((name === null || name === void 0 ? void 0 : name.getStr().toUpperCase()) === "TEXTID") {
59
+ const message = "RAISE EXCEPTION with MESSAGE, TEXTID cannot be passed";
60
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, name, message));
61
+ return;
62
+ }
63
+ }
64
+ RaiseMessage.checkClass(classTok.getStr(), input, classTok);
65
+ }
66
+ static checkThrow(node, input) {
67
+ var _a;
68
+ const classTok = (_a = node.findDirectExpression(Expressions.ClassName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
69
+ if (classTok === undefined || node.findDirectExpression(Expressions.MessageSource) === undefined) {
70
+ return;
71
+ }
72
+ RaiseMessage.checkClass(classTok.getStr(), input, classTok);
73
+ }
74
+ /** MESSAGE msg or MESSAGE ID, but not USING MESSAGE */
75
+ static hasMessage(node) {
76
+ const children = node.getChildren();
77
+ for (let i = 0; i < children.length; i++) {
78
+ const c = children[i];
79
+ if (c instanceof nodes_1.TokenNode && c.getFirstToken().getStr().toUpperCase() === "MESSAGE") {
80
+ const previous = children[i - 1];
81
+ if (previous === undefined || previous.getFirstToken().getStr().toUpperCase() !== "USING") {
82
+ return true;
83
+ }
84
+ }
85
+ }
86
+ return false;
87
+ }
88
+ static checkClass(className, input, classTok) {
89
+ const def = input.scope.findClassDefinition(className);
90
+ if (def === undefined) {
91
+ return;
92
+ }
93
+ if (RaiseMessage.isT100(def, input.scope, new Set()) === false) {
94
+ const message = "Exception class " + def.getName().toUpperCase() +
95
+ " must implement IF_T100_MESSAGE or IF_T100_DYN_MSG to be raised with MESSAGE";
96
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, classTok, message));
97
+ }
98
+ }
99
+ /** true or false when known, undefined when the hierarchy contains void parts */
100
+ static isT100(def, scope, visited) {
101
+ var _a;
102
+ const upper = def.getName().toUpperCase();
103
+ if (visited.has(upper)) {
104
+ return undefined;
105
+ }
106
+ visited.add(upper);
107
+ let unknown = false;
108
+ const interfaces = def.getImplementing().map(i => i.name.toUpperCase());
109
+ const seen = new Set();
110
+ while (interfaces.length > 0) {
111
+ const name = interfaces.pop();
112
+ if (seen.has(name)) {
113
+ continue;
114
+ }
115
+ seen.add(name);
116
+ if (T100_INTERFACES.has(name)) {
117
+ return true;
118
+ }
119
+ const idef = scope.findInterfaceDefinition(name);
120
+ if (idef === undefined) {
121
+ unknown = true;
122
+ }
123
+ else {
124
+ interfaces.push(...idef.getImplementing().map(i => i.name.toUpperCase()));
125
+ }
126
+ }
127
+ const superName = (_a = def.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
128
+ if (superName !== undefined) {
129
+ const superDef = scope.findClassDefinition(superName);
130
+ if (superDef !== undefined) {
131
+ const res = RaiseMessage.isT100(superDef, scope, visited);
132
+ if (res === true) {
133
+ return true;
134
+ }
135
+ else if (res === undefined) {
136
+ unknown = true;
137
+ }
138
+ }
139
+ else if (ROOT_EXCEPTIONS.has(superName) === false) {
140
+ unknown = true;
141
+ }
142
+ }
143
+ else if (ROOT_EXCEPTIONS.has(upper) === false) {
144
+ // not an exception class, reported elsewhere or not at all
145
+ unknown = true;
146
+ }
147
+ return unknown ? undefined : false;
148
+ }
149
+ }
150
+ exports.RaiseMessage = RaiseMessage;
151
+ //# sourceMappingURL=_raise_message.js.map
@@ -43,7 +43,14 @@ const _syntax_input_1 = require("../_syntax_input");
43
43
  // a syntax error. Other types, a dynamic offset or length and "*" (undefined) are left alone, as is
44
44
  // length 0. The offset is applied first, so the length is compared to what remains after the offset.
45
45
  // A substring of a date, time or numeric text field has type n; its bounds are not checked.
46
+ // An offset or length on a numeric field (i, int8, p, f, decfloat) is a syntax error, whatever its value.
46
47
  function substringType(context, offset, length, node, input) {
48
+ const numericName = numericTypeName(context);
49
+ if (numericName !== undefined) {
50
+ const message = `Offset or length specification not possible on a field of numeric type "${numericName}"`;
51
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message));
52
+ return basic_1.VoidType.get(_syntax_input_1.CheckSyntaxKey);
53
+ }
47
54
  if (context instanceof basic_1.DateType || context instanceof basic_1.TimeType || context instanceof basic_1.NumericType) {
48
55
  return numericSubstringType(context, offset, length);
49
56
  }
@@ -69,6 +76,30 @@ function substringType(context, offset, length, node, input) {
69
76
  }
70
77
  return context;
71
78
  }
79
+ function numericTypeName(context) {
80
+ if (context instanceof basic_1.IntegerType) {
81
+ return "I";
82
+ }
83
+ else if (context instanceof basic_1.Integer8Type) {
84
+ return "INT8";
85
+ }
86
+ else if (context instanceof basic_1.PackedType) {
87
+ return "P";
88
+ }
89
+ else if (context instanceof basic_1.FloatType || context instanceof basic_1.FloatingPointType) {
90
+ return "F";
91
+ }
92
+ else if (context instanceof basic_1.DecFloat16Type) {
93
+ return "DECFLOAT16";
94
+ }
95
+ else if (context instanceof basic_1.DecFloat34Type) {
96
+ return "DECFLOAT34";
97
+ }
98
+ else if (context instanceof basic_1.DecFloatType) {
99
+ return "DECFLOAT";
100
+ }
101
+ return undefined;
102
+ }
72
103
  function numericSubstringType(context, offset, length) {
73
104
  const hasOffset = offset !== undefined && offset > 0;
74
105
  const hasLength = length !== undefined && length > 0;
@@ -38,6 +38,7 @@ const Expressions = __importStar(require("../../2_statements/expressions"));
38
38
  const source_1 = require("./source");
39
39
  const let_1 = require("./let");
40
40
  const cond_1 = require("./cond");
41
+ const _raise_message_1 = require("../_raise_message");
41
42
  class CondBody {
42
43
  static runSyntax(node, input, targetType) {
43
44
  if (node === undefined) {
@@ -48,6 +49,9 @@ class CondBody {
48
49
  if (l) {
49
50
  scoped = let_1.Let.runSyntax(l, input);
50
51
  }
52
+ for (const t of node.findDirectExpressions(Expressions.Throw)) {
53
+ _raise_message_1.RaiseMessage.checkThrow(t, input);
54
+ }
51
55
  for (const s of node.findDirectExpressions(Expressions.Cond)) {
52
56
  cond_1.Cond.runSyntax(s, input);
53
57
  }
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.Select = void 0;
37
37
  const Expressions = __importStar(require("../../2_statements/expressions"));
38
+ const nodes_1 = require("../../nodes");
38
39
  const basic_1 = require("../../types/basic");
39
40
  const inline_data_1 = require("./inline_data");
40
41
  const target_1 = require("./target");
@@ -50,6 +51,8 @@ const _syntax_input_1 = require("../_syntax_input");
50
51
  const version_1 = require("../../../version");
51
52
  const _check_database_fields_1 = require("./_check_database_fields");
52
53
  const isSimple = /^\w+$/;
54
+ // SQL functions where the result has the same type as the first argument
55
+ const sameTypeAsFirstArgument = new Set(["UPPER", "LOWER", "LTRIM", "RTRIM"]);
53
56
  class Select {
54
57
  static runSyntax(node, input, skipImplicitInto = false, selectLoop = false) {
55
58
  var _a;
@@ -255,7 +258,7 @@ class Select {
255
258
  if (intoStructure) {
256
259
  const inlineList = intoStructure.findAllExpressions(Expressions.InlineData);
257
260
  if (inlineList.length === 1) {
258
- inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input.scope));
261
+ inline_data_1.InlineData.runSyntax(inlineList[0], input, this.buildStructureType(fields, dbSources, input.scope, from));
259
262
  }
260
263
  else {
261
264
  for (const inline of inlineList) {
@@ -285,7 +288,12 @@ class Select {
285
288
  return;
286
289
  }
287
290
  let type = basic_1.VoidType.get("SELECT_todo2");
288
- if (isSimple.test(field.code)) {
291
+ const fn = this.findFunctionColumn(field, false);
292
+ if (fn) {
293
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
294
+ type = this.inferFunctionType(fn, code => this.findFieldType(code, sourceInfos, input.scope)) || type;
295
+ }
296
+ else if (isSimple.test(field.code)) {
289
297
  for (const dbSource of dbSources) {
290
298
  if (dbSource === undefined) {
291
299
  continue;
@@ -317,7 +325,7 @@ class Select {
317
325
  return basic_1.IntegerType.get();
318
326
  }
319
327
  }
320
- static buildStructureType(fields, dbSources, scope) {
328
+ static buildStructureType(fields, dbSources, scope, from) {
321
329
  var _a, _b, _c, _d, _e, _f;
322
330
  if (fields.length === 1 && dbSources.length === 1) {
323
331
  // COUNT( * ) yields an integer regardless of the (possibly dynamic) table
@@ -353,10 +361,16 @@ class Select {
353
361
  return basic_1.IntegerType.get();
354
362
  }
355
363
  }
356
- else {
357
- // todo: aggregated/calculated values
358
- return basic_1.VoidType.get("SELECT_todo11");
364
+ const fn = this.findFunctionColumn(fields[0], false);
365
+ if (fn) {
366
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
367
+ const type = this.inferFunctionType(fn, code => this.findFieldType(code, sourceInfos, scope));
368
+ if (type) {
369
+ return type;
370
+ }
359
371
  }
372
+ // todo: aggregated/calculated values
373
+ return basic_1.VoidType.get("SELECT_todo11");
360
374
  }
361
375
  else {
362
376
  return basic_1.VoidType.get("SELECT_todo10");
@@ -377,15 +391,10 @@ class Select {
377
391
  if (!(dbType instanceof basic_1.StructureType)) {
378
392
  return basic_1.VoidType.get("SELECT_todo14");
379
393
  }
380
- const allFieldsSimple = fields.every(f => isSimple.test(f.code));
381
- if (allFieldsSimple === true) {
382
- const components = [];
383
- for (const field of fields) {
384
- const type = dbType.getComponentByName(field.code);
385
- if (type === undefined) {
386
- return basic_1.VoidType.get("SELECT_todo9");
387
- }
388
- components.push({ name: field.as || field.code, type });
394
+ if (this.allFieldsSupported(fields) === true) {
395
+ const components = this.buildSingleSourceComponents(fields, dbType, from, dbSources, scope);
396
+ if (components === undefined) {
397
+ return basic_1.VoidType.get("SELECT_todo9");
389
398
  }
390
399
  return new basic_1.StructureType(components);
391
400
  }
@@ -411,9 +420,15 @@ class Select {
411
420
  }
412
421
  return new basic_1.TableType(new basic_1.StructureType(components), tableOptions, undefined);
413
422
  }
423
+ const lookup = code => this.findFieldType(code, sourceInfos, scope);
414
424
  const components = [];
415
425
  for (const field of fields) {
416
- const type = this.findFieldType(field.code, sourceInfos, scope);
426
+ const fn = this.findFunctionColumn(field);
427
+ if (fn) {
428
+ components.push({ name: field.as, type: this.inferFunctionType(fn, lookup) || basic_1.VoidType.get("SELECT_function") });
429
+ continue;
430
+ }
431
+ const type = lookup(field.code);
417
432
  if (type === undefined) {
418
433
  return basic_1.VoidType.get("SELECT_todo3");
419
434
  }
@@ -436,20 +451,101 @@ class Select {
436
451
  if (fields.length === 1 && fields[0].code === "*") {
437
452
  return new basic_1.TableType(dbType, tableOptions, undefined);
438
453
  }
439
- const allFieldsSimple = fields.every(f => isSimple.test(f.code));
440
- if (allFieldsSimple === true) {
441
- const components = [];
442
- for (const field of fields) {
443
- const type = dbType.getComponentByName(field.code);
444
- if (type === undefined) {
445
- return basic_1.VoidType.get("SELECT_todo6");
446
- }
447
- components.push({ name: field.as || field.code, type });
454
+ if (this.allFieldsSupported(fields) === true) {
455
+ const components = this.buildSingleSourceComponents(fields, dbType, from, dbSources, scope);
456
+ if (components === undefined) {
457
+ return basic_1.VoidType.get("SELECT_todo6");
448
458
  }
449
459
  return new basic_1.TableType(new basic_1.StructureType(components), tableOptions, undefined);
450
460
  }
451
461
  return basic_1.VoidType.get("SELECT_todo7");
452
462
  }
463
+ /** plain field names, or SQL function columns with an alias */
464
+ static allFieldsSupported(fields) {
465
+ return fields.every(f => isSimple.test(f.code) || this.findFunctionColumn(f) !== undefined);
466
+ }
467
+ /** returns undefined if a plain field is not found in the database table */
468
+ static buildSingleSourceComponents(fields, dbType, from, dbSources, scope) {
469
+ const sourceInfos = this.buildDatabaseSourceInfos(from, dbSources);
470
+ const lookup = code => this.findFieldType(code, sourceInfos, scope);
471
+ const components = [];
472
+ for (const field of fields) {
473
+ const fn = this.findFunctionColumn(field);
474
+ if (fn) {
475
+ components.push({ name: field.as, type: this.inferFunctionType(fn, lookup) || basic_1.VoidType.get("SELECT_function") });
476
+ continue;
477
+ }
478
+ const type = dbType.getComponentByName(field.code);
479
+ if (type === undefined) {
480
+ return undefined;
481
+ }
482
+ components.push({ name: field.as || field.code, type });
483
+ }
484
+ return components;
485
+ }
486
+ /** returns the SQLFunction node if the field list entry is a single SQL function call */
487
+ static findFunctionColumn(field, requireAlias = true) {
488
+ if (requireAlias === true && field.as === "") {
489
+ return undefined;
490
+ }
491
+ else if (!(field.expression.get() instanceof Expressions.SQLField)) {
492
+ return undefined;
493
+ }
494
+ const children = field.expression.getChildren().filter(c => !(c.get() instanceof Expressions.SQLAsName) && c.concatTokens().toUpperCase() !== "AS");
495
+ if (children.length === 1
496
+ && children[0] instanceof nodes_1.ExpressionNode
497
+ && children[0].get() instanceof Expressions.SQLFunction) {
498
+ return children[0];
499
+ }
500
+ return undefined;
501
+ }
502
+ /** infers the result type of a SQL function, returns undefined if not possible */
503
+ static inferFunctionType(fn, lookup) {
504
+ const name = fn.getFirstToken().getStr().toUpperCase();
505
+ const inputs = fn.findDirectExpressions(Expressions.SQLFunctionInput);
506
+ if (inputs.length === 0) {
507
+ return undefined;
508
+ }
509
+ if (name === "SUBSTRING" && inputs.length === 3) {
510
+ const len = inputs[2].concatTokens();
511
+ if (/^\d+$/.test(len) === false || parseInt(len, 10) <= 0) {
512
+ return undefined;
513
+ }
514
+ const argType = this.inferFunctionInputType(inputs[0], lookup);
515
+ if (argType instanceof basic_1.StringType) {
516
+ return argType;
517
+ }
518
+ else if (argType instanceof basic_1.CharacterType
519
+ || argType instanceof basic_1.NumericType
520
+ || argType instanceof basic_1.DateType
521
+ || argType instanceof basic_1.TimeType) {
522
+ return new basic_1.CharacterType(parseInt(len, 10));
523
+ }
524
+ return undefined;
525
+ }
526
+ else if (sameTypeAsFirstArgument.has(name)) {
527
+ const argType = this.inferFunctionInputType(inputs[0], lookup);
528
+ if (argType instanceof basic_1.CharacterType || argType instanceof basic_1.StringType) {
529
+ return argType;
530
+ }
531
+ return undefined;
532
+ }
533
+ return undefined;
534
+ }
535
+ static inferFunctionInputType(input, lookup) {
536
+ const children = input.getChildren();
537
+ if (children.length !== 1 || !(children[0] instanceof nodes_1.ExpressionNode)) {
538
+ return undefined;
539
+ }
540
+ const child = children[0];
541
+ if (child.get() instanceof Expressions.SQLFieldName || child.get() instanceof Expressions.SQLAliasField) {
542
+ return lookup(child.concatTokens().toUpperCase());
543
+ }
544
+ else if (child.get() instanceof Expressions.SQLFunction) {
545
+ return this.inferFunctionType(child, lookup);
546
+ }
547
+ return undefined;
548
+ }
453
549
  static buildDatabaseSourceInfos(from, dbSources) {
454
550
  const fromSources = from.findAllExpressions(Expressions.SQLFromSource);
455
551
  return dbSources.map((source, index) => {
@@ -484,16 +580,20 @@ class Select {
484
580
  return undefined;
485
581
  }
486
582
  static findFields(node, input) {
487
- var _a, _b;
488
- const expr = node.findFirstExpression(Expressions.SQLFieldList);
583
+ var _a, _b, _c;
584
+ let expr = node.findFirstExpression(Expressions.SQLFieldList);
585
+ // a single field can be wrapped in a nested SQLFieldList
586
+ while (expr && expr.getChildren().length === 1 && ((_a = expr.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.SQLFieldList) {
587
+ expr = expr.getFirstChild();
588
+ }
489
589
  const ret = [];
490
- if (((_a = expr === null || expr === void 0 ? void 0 : expr.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Dynamic) {
590
+ if (((_b = expr === null || expr === void 0 ? void 0 : expr.getFirstChild()) === null || _b === void 0 ? void 0 : _b.get()) instanceof Expressions.Dynamic) {
491
591
  dynamic_1.Dynamic.runSyntax(expr.getFirstChild(), input);
492
592
  }
493
593
  // eslint-disable-next-line max-len
494
594
  for (const field of (expr === null || expr === void 0 ? void 0 : expr.findDirectExpressionsMulti([Expressions.SQLField, Expressions.SQLFieldName, Expressions.SQLAggregation])) || []) {
495
595
  let code = field.concatTokens().toUpperCase();
496
- const as = ((_b = field.findDirectExpression(Expressions.SQLAsName)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "";
596
+ const as = ((_c = field.findDirectExpression(Expressions.SQLAsName)) === null || _c === void 0 ? void 0 : _c.concatTokens()) || "";
497
597
  if (as !== "") {
498
598
  code = code.replace(" AS " + as.toUpperCase(), "");
499
599
  }
@@ -392,8 +392,9 @@ class Source {
392
392
  /** The calculation type of an arithmetic expression is the most general of the
393
393
  * operand types. An operand of type c, n, d, t or string is converted into it and
394
394
  * never becomes the result: "lv_f * '0.25'" is a float, not a character field of
395
- * length four. Returns undefined when neither operand is numeric, leaving the
396
- * decision to the caller. */
395
+ * length four. Date and time operands count as numbers of days and seconds, type i:
396
+ * "lv_end - lv_start" is a number of days, not a date. Returns undefined when neither
397
+ * operand is numeric, leaving the decision to the caller. */
397
398
  static calculationType(left, right) {
398
399
  if (left === undefined || right === undefined) {
399
400
  return undefined;
@@ -405,12 +406,27 @@ class Source {
405
406
  else if (right instanceof basic_1.VoidType || right instanceof unknown_type_1.UnknownType) {
406
407
  return right;
407
408
  }
409
+ const dateOrTime = left instanceof basic_1.DateType || left instanceof basic_1.TimeType
410
+ || right instanceof basic_1.DateType || right instanceof basic_1.TimeType;
411
+ if (left instanceof basic_1.DateType || left instanceof basic_1.TimeType) {
412
+ left = basic_1.IntegerType.get();
413
+ }
414
+ if (right instanceof basic_1.DateType || right instanceof basic_1.TimeType) {
415
+ right = basic_1.IntegerType.get();
416
+ }
408
417
  const leftRank = this.numericRank(left);
409
418
  const rightRank = this.numericRank(right);
410
419
  if (leftRank === undefined && rightRank === undefined) {
411
420
  return undefined;
412
421
  }
413
- else if (rightRank === undefined) {
422
+ // a character-like operand next to a date or time counts as p: "lv_date + '5'" is p
423
+ if (leftRank === undefined && this.isCharacterLike(left) && dateOrTime) {
424
+ return rightRank >= 3 ? right : new basic_1.PackedType(8, 0);
425
+ }
426
+ else if (rightRank === undefined && this.isCharacterLike(right) && dateOrTime) {
427
+ return leftRank >= 3 ? left : new basic_1.PackedType(8, 0);
428
+ }
429
+ if (rightRank === undefined) {
414
430
  return left;
415
431
  }
416
432
  else if (leftRank === undefined) {
@@ -418,6 +434,9 @@ class Source {
418
434
  }
419
435
  return leftRank >= rightRank ? left : right;
420
436
  }
437
+ static isCharacterLike(type) {
438
+ return type instanceof basic_1.CharacterType || type instanceof basic_1.NumericType || type instanceof basic_1.StringType;
439
+ }
421
440
  static numericRank(type) {
422
441
  if (type instanceof basic_1.DecFloat34Type) {
423
442
  return 6;
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.SwitchBody = void 0;
37
37
  const Expressions = __importStar(require("../../2_statements/expressions"));
38
38
  const source_1 = require("./source");
39
+ const _raise_message_1 = require("../_raise_message");
39
40
  const _syntax_input_1 = require("../_syntax_input");
40
41
  const basic_1 = require("../../types/basic");
41
42
  class SwitchBody {
@@ -43,6 +44,9 @@ class SwitchBody {
43
44
  if (node === undefined) {
44
45
  return;
45
46
  }
47
+ for (const t of node.findDirectExpressions(Expressions.Throw)) {
48
+ _raise_message_1.RaiseMessage.checkThrow(t, input);
49
+ }
46
50
  const thenSource = node.findExpressionAfterToken("THEN");
47
51
  if (!((thenSource === null || thenSource === void 0 ? void 0 : thenSource.get()) instanceof Expressions.Source)) {
48
52
  const message = "SwitchBody, unexpected";
@@ -44,6 +44,7 @@ const raise_with_1 = require("../expressions/raise_with");
44
44
  const _object_oriented_1 = require("../_object_oriented");
45
45
  const method_parameters_1 = require("../expressions/method_parameters");
46
46
  const _syntax_input_1 = require("../_syntax_input");
47
+ const _raise_message_1 = require("../_raise_message");
47
48
  class Raise {
48
49
  runSyntax(node, input) {
49
50
  // todo
@@ -103,6 +104,7 @@ class Raise {
103
104
  if (param) {
104
105
  new method_parameters_1.MethodParameters().checkExporting(param, input, method, true);
105
106
  }
107
+ _raise_message_1.RaiseMessage.checkRaise(node, input);
106
108
  for (const s of node.findDirectExpressions(Expressions.RaiseWith)) {
107
109
  raise_with_1.RaiseWith.runSyntax(s, input);
108
110
  }
@@ -0,0 +1,91 @@
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.Try = void 0;
37
+ const Expressions = __importStar(require("../../2_statements/expressions"));
38
+ const Statements = __importStar(require("../../2_statements/statements"));
39
+ const Structures = __importStar(require("../../3_structures/structures"));
40
+ const _syntax_input_1 = require("../_syntax_input");
41
+ // "special exceptions must be caught before general exceptions", a CATCH of a class that inherits
42
+ // from a class named in an earlier CATCH of the same TRY can never be reached, this is a syntax error
43
+ // only reported when the lineage of the later class is known up to the earlier class, void classes are skipped
44
+ class Try {
45
+ static runSyntax(node, input) {
46
+ const caught = new Set();
47
+ for (const catchStructure of node.findDirectStructures(Structures.Catch)) {
48
+ const statement = catchStructure.findDirectStatement(Statements.Catch);
49
+ if (statement === undefined) {
50
+ continue;
51
+ }
52
+ const names = [];
53
+ for (const c of statement.findDirectExpressions(Expressions.ClassName)) {
54
+ const token = c.getFirstToken();
55
+ const className = token.getStr().toUpperCase();
56
+ names.push(className);
57
+ if (caught.size === 0) {
58
+ continue;
59
+ }
60
+ const superclass = this.findCaughtSuperclass(className, caught, input);
61
+ if (superclass !== undefined) {
62
+ const message = `CATCH of ${className} after the CATCH of its superclass ${superclass}`;
63
+ input.issues.push((0, _syntax_input_1.syntaxIssue)(input, token, message));
64
+ return;
65
+ }
66
+ }
67
+ for (const name of names) {
68
+ caught.add(name);
69
+ }
70
+ }
71
+ }
72
+ static findCaughtSuperclass(className, caught, input) {
73
+ var _a;
74
+ const visited = new Set([className]);
75
+ let current = input.scope.findClassDefinition(className);
76
+ while (current !== undefined) {
77
+ const superclass = (_a = current.getSuperClass()) === null || _a === void 0 ? void 0 : _a.toUpperCase();
78
+ if (superclass === undefined || visited.has(superclass)) {
79
+ return undefined;
80
+ }
81
+ else if (caught.has(superclass)) {
82
+ return superclass;
83
+ }
84
+ visited.add(superclass);
85
+ current = input.scope.findClassDefinition(superclass);
86
+ }
87
+ return undefined;
88
+ }
89
+ }
90
+ exports.Try = Try;
91
+ //# sourceMappingURL=try.js.map
@@ -51,6 +51,7 @@ const types_1 = require("./structures/types");
51
51
  const statics_1 = require("./structures/statics");
52
52
  const constants_1 = require("./structures/constants");
53
53
  const cleanup_1 = require("./structures/cleanup");
54
+ const try_1 = require("./structures/try");
54
55
  const class_definition_1 = require("../types/class_definition");
55
56
  const interface_definition_1 = require("../types/interface_definition");
56
57
  const delete_memory_1 = require("./statements/delete_memory");
@@ -536,6 +537,9 @@ class SyntaxLogic {
536
537
  else if (stru instanceof Structures.Cleanup) {
537
538
  cleanup_1.Cleanup.runSyntax(node, input);
538
539
  }
540
+ else if (stru instanceof Structures.Try) {
541
+ try_1.Try.runSyntax(node, input);
542
+ }
539
543
  return false;
540
544
  }
541
545
  updateScopeStatement(node) {
@@ -75,7 +75,7 @@ class Registry {
75
75
  }
76
76
  static abaplintVersion() {
77
77
  // magic, see build script "version.js"
78
- return "2.120.99";
78
+ return "2.120.101";
79
79
  }
80
80
  getDDICReferences() {
81
81
  return this.ddicReferences;
@@ -79,13 +79,18 @@ class FullyTypeConstants extends _abap_rule_1.ABAPRule {
79
79
  if ((stat.get() instanceof Statements.Constant
80
80
  || (this.conf.checkData === true && stat.get() instanceof Statements.Data))
81
81
  && !this.isTyped(stat)) {
82
+ if (stat.get() instanceof Statements.Data && stat.findDirectExpression(expressions_1.DataDefinition) === undefined) {
83
+ // unnamed field, eg. "DATA (10)." inside DATA BEGIN OF, cannot be typed
84
+ continue;
85
+ }
82
86
  const type = stat.get() instanceof Statements.Constant ? "constant definition" : "data definition";
83
87
  let token = (_a = stat.findFirstExpression(expressions_1.NamespaceSimpleName)) === null || _a === void 0 ? void 0 : _a.getFirstToken();
84
88
  if (token === undefined) {
85
89
  token = (_b = stat.findFirstExpression(expressions_1.DefinitionName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
86
90
  }
87
91
  if (token === undefined) {
88
- throw new Error("fully type constants, unexpected node");
92
+ const start = stat.getFirstToken().getStart();
93
+ throw new Error(`fully type constants: unexpected node, ${file.getFilename()}, row ${start.getRow()}, col ${start.getCol()}, statement "${stat.concatTokens()}"`);
89
94
  }
90
95
  issues.push(issue_1.Issue.atToken(file, token, this.getDescription(type), this.getMetadata().key, this.conf.severity));
91
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/core",
3
- "version": "2.120.99",
3
+ "version": "2.120.101",
4
4
  "description": "abaplint - Core API",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/abaplint.d.ts",