All files / src/abap/5_syntax/expressions source.ts

96.74% Statements 506/523
87.65% Branches 206/235
100% Functions 10/10
96.74% Lines 506/523

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 5241x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12408x 12408x 12408x 12408x 12408x 12408x 12408x 12408x 29x 29x 12379x 12379x 12379x 12379x 12408x 855x 855x 855x 855x 855x 855x 855x 11x 855x 15x 15x 15x 15x 15x 15x 855x 75x 75x 75x 75x 75x 75x 855x 42x 42x 42x 42x 2x 42x 40x 40x 42x 42x 42x 855x 14x 14x 14x 14x 6x 14x 8x 8x 14x 14x 855x 46x 46x 46x 46x 46x 46x 46x 46x 14x 46x 32x 32x 46x 46x 46x 46x 46x 46x 46x 855x 162x 162x 162x 162x 162x 1x 1x 1x 162x 1x 1x 1x 1x 162x 15x 15x 15x 15x 15x 145x 145x 145x 145x 855x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 7x 59x 31x 2x 31x 29x 29x 52x 1x 1x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 59x 855x 9x 9x 9x 9x 5x 9x 4x 4x 9x 9x 5x 9x 4x 4x 9x 855x 23x 23x 23x 23x 23x 23x 23x 2x 2x 2x 2x 21x 21x 21x 21x 855x 4x 4x 4x 4x 4x 4x 855x 395x 395x 395x 395x 38x 395x 356x 356x 395x 395x 855x   855x 12408x     11535x 11535x 11535x 11535x 12408x 11534x 11534x 12408x 86x 86x 11535x 11535x 11535x 11535x 11535x 11535x 12408x 12230x 12148x 12148x 1235x 1235x 1235x 3x 3x 3x 3x 12148x 1x 1x 10913x 7100x 7100x 10912x 282x 3812x 308x 308x 3530x 2909x 2909x 3222x 32x 3x 3x 3x 3x 29x 313x 3x 281x 247x 247x 3x 3x 247x 247x 10x 10x 10x 278x 14x 14x 12148x 12221x 12230x 19x 19x 19x 19x 19x 19x 5x 5x 5x 5x 19x 5x 5x 14x 14x 12216x 12216x 12230x 11521x 11521x 12230x 11521x 12408x 57x 57x 11464x 11464x 11464x 1x 1x 1x 1x 248x 248x 9x 9x 248x 1x 1x 3217x 246x 246x 236x 236x 246x 3217x   3217x   2981x   2981x 2981x 2981x 3217x 1x 1x 1x 1x 1x 1x 1x 1x 246x   246x 2x 2x 246x 5x 5x 239x 246x 246x 246x 15x 15x 246x 5x 5x 239x 239x 239x 246x 10x 10x 229x 229x 246x 1x 246x 1x 1x 227x 246x 11x 246x 4x 4x 246x 246x 1x 1x 17x 17x 1x 1x 478x 2x 478x   476x 40x 476x 37x 436x 3x 399x 359x 359x 37x 37x 1x 1x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 1006x 983x 983x 535x 535x 983x 250x 250x 250x 250x 250x     448x 198x 198x 198x 983x 1006x 1006x 1x 1x 1x 15x 6x 15x 2x 9x 2x 2x 5x 5x 1x 1x 754x 754x 754x 754x 754x 754x 754x 754x 754x 754x   754x 265x 265x 489x 754x 398x 398x 2x     2x 2x 2x 2x 2x 398x         396x 396x 396x 91x 91x 91x 1x 1x 1x 32x 32x 32x 32x 32x 32x 32x 1x 1x  
import {ExpressionNode, TokenNode} from "../../nodes";
import {AbstractType} from "../../types/basic/_abstract_type";
import * as Expressions from "../../2_statements/expressions";
import {MethodCallChain} from "./method_call_chain";
import {UnknownType} from "../../types/basic/unknown_type";
import {FieldChain} from "./field_chain";
import {VoidType, StringType, CharacterType, DataReference, ObjectReferenceType, FloatType, IntegerType, Integer8Type, PackedType, DecFloat16Type, DecFloat34Type, XSequenceType, XStringType, HexType, XGenericType, AnyType, CLikeType, CSequenceType, NumericGenericType, DecFloatType, DateType, TimeType, NumericType} from "../../types/basic";
import {Constant} from "./constant";
import {BasicTypes} from "../basic_types";
import {ComponentChain} from "./component_chain";
import {StringTemplate} from "./string_template";
import {ValueBody} from "./value_body";
import {Cond} from "./cond";
import {ReduceBody} from "./reduce_body";
import {ReferenceType} from "../_reference";
import {SwitchBody} from "./switch_body";
import {CondBody} from "./cond_body";
import {ConvBody} from "./conv_body";
import {FilterBody} from "./filter_body";
import {CorrespondingBody} from "./corresponding_body";
import {BuiltIn} from "../_builtin";
import {AttributeChain} from "./attribute_chain";
import {Dereference} from "./dereference";
import {Cast} from "./cast";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {TypeUtils} from "../_type_utils";
import {CheckSyntaxKey, SyntaxInput, syntaxIssue} from "../_syntax_input";
import {AssertError} from "../assert_error";
import {LanguageVersion, Release, releaseAtLeast} from "../../../version";
 
/*
* Type interference, valid scenarios:
* typed = VALUE #( ... ).         right hand side must follow left hand type
* DATA(bar) = VALUE type( ... ).  left gets the type of rigthand
* typed = VALUE type( ... ).      types must match and be compatible???
************* ERRORS *********
* VALUE #( ... ).                 syntax error
* DATA(bar) = VALUE #( ... ).     give error, no type can be derived
*/
 
// TODO: refactor all these method parameters to objects, this is getting messy
export class Source {
  public static runSyntax(
    node: ExpressionNode | undefined,
    input: SyntaxInput,
    targetType?: AbstractType,
    writeReference = false,
    allowGenericDeference = false,
    readReference = true): AbstractType | undefined {
 
    if (node === undefined) {
      return undefined;
    }
 
    const children = node.getChildren().slice();
    let first = children.shift();
 
    if (first instanceof TokenNode) {
      const token = first.getFirstToken();
      const tok = token.getStr().toUpperCase();
      switch (tok) {
        case "(":
        case "-":
        case "+":
        case "BIT":
          break;
        case "BOOLC":
        {
          const method = BuiltIn.searchBuiltin(tok);
          input.scope.addReference(token, method, ReferenceType.BuiltinMethodReference, input.filename);
          Cond.runSyntax(node.findDirectExpression(Expressions.Cond)!, input);
          return StringType.get();
        }
        case "XSDBOOL":
        {
          const method = BuiltIn.searchBuiltin(tok);
          input.scope.addReference(token, method, ReferenceType.BuiltinMethodReference, input.filename);
          Cond.runSyntax(node.findDirectExpression(Expressions.Cond)!, input);
          return new CharacterType(1, {qualifiedName: "ABAP_BOOL", ddicName: "ABAP_BOOL"});
        }
        case "REDUCE":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = ReduceBody.runSyntax(node.findDirectExpression(Expressions.ReduceBody), input, foundType);
          if (foundType === undefined || foundType.isGeneric()) {
            this.addIfInferred(node, input, bodyType);
          } else {
            this.addIfInferred(node, input, foundType);
          }
          this.traverseRemainingChildren(children, input);
          return foundType ? foundType : bodyType;
        }
        case "SWITCH":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = SwitchBody.runSyntax(node.findDirectExpression(Expressions.SwitchBody), input, foundType);
          if (foundType === undefined || foundType.isGeneric()) {
            this.addIfInferred(node, input, bodyType);
          } else {
            this.addIfInferred(node, input, foundType);
          }
          return foundType ? foundType : bodyType;
        }
        case "COND":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = CondBody.runSyntax(node.findDirectExpression(Expressions.CondBody), input, foundType);
          /*
          console.log("COND BODY type;:");
          console.dir(bodyType);
          */
          if (foundType === undefined || foundType.isGeneric()) {
            this.addIfInferred(node, input, bodyType);
          } else {
            this.addIfInferred(node, input, foundType);
          }
          children.shift();
          children.shift();
          children.shift();
          children.shift();
          this.traverseRemainingChildren(children, input);
          return foundType ? foundType : bodyType;
        }
        case "CONV":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = ConvBody.runSyntax(node.findDirectExpression(Expressions.ConvBody)!, input, foundType);
          const inferred = node.findDirectExpression(Expressions.TypeNameOrInfer)?.concatTokens();
          if (new TypeUtils(input.scope).isConvable(foundType, bodyType) === false) {
            const message = `CONV: Types not compatible, ${foundType?.constructor.name}, ${bodyType?.constructor.name}`;
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
            return VoidType.get(CheckSyntaxKey);
          } else if (foundType?.isGeneric() && inferred !== "#") {
            const message = "Cannot CONV to generic type";
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
            return VoidType.get(CheckSyntaxKey);
          }
          if (foundType?.isGeneric() && bodyType !== undefined) {
            const derived = this.inferGenericConv(foundType, input) || bodyType;
            this.addIfInferred(node, input, derived);
            this.traverseRemainingChildren(children, input);
            return derived;
          }
          this.addIfInferred(node, input, foundType);
          this.traverseRemainingChildren(children, input);
          return foundType;
        }
        case "REF":
        {
          let foundType = this.determineType(node, input, targetType);
          const s = Source.runSyntax(node.findDirectExpression(Expressions.Source), input);
          /*
          console.dir(node.concatTokens());
          console.dir(s);
          console.dir(foundType);
          console.dir(targetType);
          */
 
          if (foundType && foundType.isGeneric() && s) {
            foundType = new DataReference(s);
          } else if (foundType === undefined && s) {
            if (s instanceof AnyType) {
              foundType = new DataReference(VoidType.get("REF-ANY"));
            } else {
              foundType = new DataReference(s);
            }
          } else if (foundType && targetType === undefined) {
            foundType = new DataReference(foundType);
          }
 
          /*
          if (targetType && !(targetType instanceof DataReference)) {
            const message = `REF: Types not compatible, ` + targetType.constructor.name;
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
          }
          */
 
          this.addIfInferred(node, input, foundType);
          return foundType;
        }
        case "FILTER":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = FilterBody.runSyntax(node.findDirectExpression(Expressions.FilterBody), input, foundType);
          if (foundType === undefined || foundType.isGeneric()) {
            this.addIfInferred(node, input, bodyType);
          } else {
            this.addIfInferred(node, input, foundType);
          }
 
          if (foundType && !(foundType instanceof UnknownType)) {
            return foundType;
          } else {
            return bodyType;
          }
        }
        case "CORRESPONDING":
        {
          const foundType = this.determineType(node, input, targetType);
          if (foundType?.isGeneric() === true
              && node.findDirectExpression(Expressions.TypeNameOrInfer)?.concatTokens() === "#"
              && !releaseAtLeast(input.scope.getRelease(), Release.v756)
              && input.scope.getLanguageVersion() !== LanguageVersion.Cloud
              && !input.scope.getOpenABAP()) {
            const message = "CORRESPONDING #, the type of the target is generic";
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
            return VoidType.get(CheckSyntaxKey);
          }
          CorrespondingBody.runSyntax(node.findDirectExpression(Expressions.CorrespondingBody), input, foundType);
          this.addIfInferred(node, input, foundType);
          return foundType;
        }
        case "EXACT":
        {
          const foundType = this.determineType(node, input, targetType);
          Source.runSyntax(node.findDirectExpression(Expressions.Source), input, foundType);
          this.addIfInferred(node, input, foundType);
          return foundType;
        }
        case "VALUE":
        {
          const foundType = this.determineType(node, input, targetType);
          const bodyType = ValueBody.runSyntax(node.findDirectExpression(Expressions.ValueBody), input, foundType);
          if (foundType === undefined || foundType.isGeneric()) {
            this.addIfInferred(node, input, bodyType);
          } else {
            this.addIfInferred(node, input, foundType);
          }
          return foundType ? foundType : bodyType;
        }
        default:
          return new UnknownType("todo, Source type " + tok);
      }
    } else if (first === undefined || !(first instanceof ExpressionNode)) {
      return undefined;
    }
 
    let context: AbstractType | undefined = new UnknownType("todo, Source type");
 
    const type: ReferenceType[] = [];
    if (readReference) {
      type.push(ReferenceType.DataReadReference);
    }
    if (writeReference) {
      type.push(ReferenceType.DataWriteReference);
    }
 
    let hexExpected = false;
    let hexNext = false;
    // an arithmetic operator has been seen, so the operands that follow
    // determine a calculation type rather than simply replacing the context
    let arithmetic = false;
    while (children.length >= 0) {
      if (first instanceof ExpressionNode) {
        const get = first.get();
        if (get instanceof Expressions.MethodCallChain) {
          const found = MethodCallChain.runSyntax(first, input, targetType);
          context = arithmetic === true ? this.infer(context, found, true) : found;
          if (context === undefined) {
            const message = "Method has no RETURNING value";
            input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
            return VoidType.get(CheckSyntaxKey);
          }
        } else if (get instanceof Expressions.Cast) {
          const found = Cast.runSyntax(first, input, targetType);
          context = arithmetic === true ? this.infer(context, found, true) : found;
        } else if (get instanceof Expressions.FieldChain) {
          const found = FieldChain.runSyntax(first, input, type, allowGenericDeference);
          context = arithmetic === true ? this.infer(context, found, true) : found;
        } else if (get instanceof Expressions.StringTemplate) {
          context = StringTemplate.runSyntax(first, input);
        } else if (get instanceof Expressions.Source) {
          const found = Source.runSyntax(first, input);
          context = this.infer(context, found, arithmetic);
        } else if (get instanceof Expressions.Constant) {
          const found = Constant.runSyntax(first);
          context = this.infer(context, found, arithmetic);
        } else if (get instanceof Expressions.Dereference) {
          if (this.isNewObjectDereference(node, first)) {
            const message = "NEW cannot be dereferenced directly";
            input.issues.push(syntaxIssue(input, first.getFirstToken(), message));
            return VoidType.get(CheckSyntaxKey);
          }
          context = Dereference.runSyntax(first, context, input);
        } else if (get instanceof Expressions.ComponentChain) {
          context = ComponentChain.runSyntax(context, first, input);
        } else if (get instanceof Expressions.ArithOperator) {
          arithmetic = true;
          if (first.concatTokens() === "**") {
            context = new FloatType();
          }
          const operator = first.concatTokens().toUpperCase();
          if (operator === "BIT-OR" || operator === "BIT-AND" || operator === "BIT-XOR") {
            hexExpected = true;
            hexNext = true;
          }
        } else if (get instanceof Expressions.AttributeChain) {
          context = AttributeChain.runSyntax(context, first, input, type);
        }
      }
 
      if (hexExpected === true) {
        if (!(context instanceof VoidType)
            && !(context instanceof XStringType)
            && !(context instanceof HexType)
            && !(context instanceof XGenericType)
            && !(context instanceof XSequenceType)
            && !(context instanceof UnknownType)) {
          const message = "Operator only valid for XSTRING or HEX";
          input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
          return VoidType.get(CheckSyntaxKey);
        }
        if (hexNext === false) {
          hexExpected = false;
        }
        hexNext = false;
      }
 
      first = children.shift();
      if (first === undefined) {
        break;
      }
    }
 
    if (node.findDirectTokenByText("&&")) {
      return StringType.get();
    }
 
    return context;
  }
 
////////////////////////////////
 
  private static traverseRemainingChildren(children: (ExpressionNode | TokenNode)[], input: SyntaxInput) {
    const last = children[children.length - 1];
    if (last && last.get() instanceof Expressions.Source) {
      Source.runSyntax(last as ExpressionNode, input);
    }
  }
 
  private static infer(context: AbstractType | undefined, found: AbstractType | undefined, arithmetic = false) {
    if (arithmetic === true) {
      const calculation = this.calculationType(context, found);
      if (calculation !== undefined) {
        return calculation;
      }
    }
    if (context instanceof FloatType && found instanceof IntegerType) {
      return context;
    } else if (context instanceof IntegerType && found instanceof HexType) {
      return context;
    } else if ((context instanceof IntegerType || context instanceof FloatType) && found?.isGeneric()) {
      return context;
    } else {
      return found;
    }
  }
 
  /** The calculation type of an arithmetic expression is the most general of the
   * operand types. An operand of type c, n, d, t or string is converted into it and
   * never becomes the result: "lv_f * '0.25'" is a float, not a character field of
   * length four. Date and time operands count as numbers of days and seconds, type i:
   * "lv_end - lv_start" is a number of days, not a date. Returns undefined when neither
   * operand is numeric, leaving the decision to the caller. */
  private static calculationType(left: AbstractType | undefined, right: AbstractType | undefined) {
    if (left === undefined || right === undefined) {
      return undefined;
    } else if (left instanceof VoidType || left instanceof UnknownType) {
      // not knowing an operand means not knowing the result
      return left;
    } else if (right instanceof VoidType || right instanceof UnknownType) {
      return right;
    }
 
    const dateOrTime = left instanceof DateType || left instanceof TimeType
      || right instanceof DateType || right instanceof TimeType;
    if (left instanceof DateType || left instanceof TimeType) {
      left = IntegerType.get();
    }
    if (right instanceof DateType || right instanceof TimeType) {
      right = IntegerType.get();
    }
 
    const leftRank = this.numericRank(left);
    const rightRank = this.numericRank(right);
    if (leftRank === undefined && rightRank === undefined) {
      return undefined;
    }
 
    // a character-like operand next to a date or time counts as p: "lv_date + '5'" is p
    if (leftRank === undefined && this.isCharacterLike(left) && dateOrTime) {
      return rightRank! >= 3 ? right : new PackedType(8, 0);
    } else if (rightRank === undefined && this.isCharacterLike(right) && dateOrTime) {
      return leftRank! >= 3 ? left : new PackedType(8, 0);
    }
 
    if (rightRank === undefined) {
      return left;
    } else if (leftRank === undefined) {
      return right;
    }
    return leftRank >= rightRank ? left : right;
  }
 
  private static isCharacterLike(type: AbstractType): boolean {
    return type instanceof CharacterType || type instanceof NumericType || type instanceof StringType;
  }
 
  private static numericRank(type: AbstractType): number | undefined {
    if (type instanceof DecFloat34Type) {
      return 6;
    } else if (type instanceof DecFloat16Type) {
      return 5;
    } else if (type instanceof FloatType) {
      return 4;
    } else if (type instanceof PackedType) {
      return 3;
    } else if (type instanceof Integer8Type) {
      return 2;
    } else if (type instanceof IntegerType) {
      return 1;
    }
    return undefined;
  }
 
  public static addIfInferred(
    node: ExpressionNode,
    input: SyntaxInput,
    inferredType: AbstractType | undefined): void {
 
    const basic = new BasicTypes(input);
    const typeExpression = node.findDirectExpression(Expressions.TypeNameOrInfer);
    const typeToken = typeExpression?.getFirstToken();
//    const typeName = typeToken?.getStr();
 
    /*
    console.dir(inferredType);
    console.dir(typeToken);
    */
 
    if (inferredType && typeToken) {
      const found = basic.lookupQualifiedName(inferredType.getQualifiedName());
      if (found) {
        const tid = new TypedIdentifier(typeToken, input.filename, inferredType);
        input.scope.addReference(typeToken, tid, ReferenceType.InferredType, input.filename, {foundQualified: true});
      } else if (inferredType instanceof ObjectReferenceType) {
        const def = input.scope.findObjectDefinition(inferredType.getQualifiedName());
        const tid = new TypedIdentifier(typeToken, input.filename, inferredType);
        if (def) {
          input.scope.addReference(typeToken, tid, ReferenceType.InferredType, input.filename, {foundQualified: true});
        } else {
          input.scope.addReference(typeToken, tid, ReferenceType.InferredType, input.filename, {foundQualified: false});
        }
      } else {
        const tid = new TypedIdentifier(typeToken, input.filename, inferredType);
        input.scope.addReference(typeToken, tid, ReferenceType.InferredType, input.filename, {foundQualified: false});
      }
    }
 
  }
 
  /** CONV #( ) at a generic operand position, the type ABAP derives for the # */
  private static inferGenericConv(foundType: AbstractType, input: SyntaxInput): AbstractType | undefined {
    if (foundType instanceof CLikeType || foundType instanceof CSequenceType) {
      return input.scope.getDDIC().lookupBuiltinType("STRING");
    } else if (foundType instanceof XSequenceType) {
      return input.scope.getDDIC().lookupBuiltinType("XSTRING");
    } else if (foundType instanceof NumericGenericType || foundType instanceof DecFloatType) {
      return input.scope.getDDIC().lookupBuiltinType("DECFLOAT34", undefined, undefined, "DECFLOAT34");
    }
    return undefined;
  }
 
  private static determineType(
    node: ExpressionNode,
    input: SyntaxInput,
    targetType: AbstractType | undefined): AbstractType | undefined {
 
    const basic = new BasicTypes(input);
    const typeExpression = node.findDirectExpression(Expressions.TypeNameOrInfer);
    const typeToken = typeExpression?.getFirstToken();
    const typeName = typeToken?.getStr();
 
    if (typeExpression === undefined) {
      throw new AssertError("determineType, child TypeNameOrInfer not found");
    } else if (typeName === "#" && targetType) {
      return targetType;
    }
 
    if (typeName !== "#" && typeToken) {
      const found = basic.parseType(typeExpression);
      if (found && found instanceof UnknownType) {
        if (input.scope.getDDIC().inErrorNamespace(typeName) === false) {
          input.scope.addReference(typeToken, undefined, ReferenceType.VoidType, input.filename);
          return VoidType.get(typeName);
        } else {
          const tid = new TypedIdentifier(typeToken, input.filename, found);
          input.scope.addReference(typeToken, tid, ReferenceType.TypeReference, input.filename);
          return found;
        }
      } else if (found === undefined) {
        const message = "Type \"" + typeName + "\" not found in scope, VALUE";
        input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
        return VoidType.get(CheckSyntaxKey);
      }
 
      return found;
    }
 
    return targetType;
  }
 
  // "NEW ty( )->*" is a syntax error, also in releases where a method call can be dereferenced
  private static isNewObjectDereference(node: ExpressionNode, deref: ExpressionNode): boolean {
    const children = node.getChildren();
    const before = children[children.indexOf(deref) - 1];
    return before instanceof ExpressionNode
      && before.get() instanceof Expressions.MethodCallChain
      && before.getChildren().length === 1
      && before.getFirstChild()?.get() instanceof Expressions.NewObject;
  }
 
}