memberSet method

  1. @override
void memberSet(
  1. String varName,
  2. dynamic varValue, {
  3. String? from,
})
override

Assign a value to a static member of this HTClass.

Implementation

@override
void memberSet(String varName, dynamic varValue, {String? from}) {
  final setter = '${InternalIdentifier.setter}$varName';

  if (isExternal) {
    externalClass!.memberSet('$id.$varName', varValue);
    return;
  } else {
    if (namespace.symbols.containsKey(varName)) {
      final decl = namespace.symbols[varName]!;
      if (decl.isStatic) {
        if (decl.isPrivate &&
            from != null &&
            !from.startsWith(namespace.fullName)) {
          throw HTError.privateMember(varName);
        }
        decl.resolve();
        decl.value = varValue;
        return;
      }
      // TODO: non-static error prompt
    } else if (namespace.symbols.containsKey(setter)) {
      final decl = namespace.symbols[setter]!;
      if (decl.isStatic) {
        if (decl.isPrivate &&
            from != null &&
            !from.startsWith(namespace.fullName)) {
          throw HTError.privateMember(varName);
        }
        decl.resolve();
        final setterFunc = decl as HTFunction;
        setterFunc.call(positionalArgs: [varValue]);
        return;
      }
      // TODO: non-static error prompt
    }
  }

  throw HTError.undefined(varName,
      filename: interpreter.currentFileName,
      line: interpreter.currentLine,
      column: interpreter.currentColumn);
}