overload (--)

Inputs

Outputs

overload creates a pending overload specifier in the current scope.

That pending specifier is consumed by the next successful local creation. Intervening operations do not consume it.

Known issue: when that local is a field created inside { ... } while another name exists in its module or in an already loaded module, such as an imported name, an earlier local or field, or a -D definition, mplc can abort: it prints an internal assertion, such as NameItem.key is inconsistent, and stops without Compilation failed. Mentioning the field's name after the Dict, as when calling a builtin of that name, can also make mplc abort the same way or fail compilation with a wrong diagnostic. Make such a field the first name of its module, before any use, load that module before any other, pass no -D definition, and give the field a name that no builtin has.

A public overload can be selected directly by module loading. A private overload participates in same-name lookup only after its module has already been loaded through some other public name.

When followed by use, the pending specifier marks every directly imported name as an overload and clears when the import completes, including an empty import.

Behavior

Example

overloadExample.mpl

private overload virtual hiddenHelper: 3;
overload virtual helper: 1;
virtual publicAgain: 2;

test.mpl

"overloadExample.helper" use

{} 0 {} [
  "-- directly selected public overload --" printCompilerMessage
  helper printStack _:;
  0
] "main" exportFunction

Expected Output During Compilation

-- directly selected public overload --
1

indirectLookupExample.mpl

"overloadExample.publicAgain" use

{} 0 {} [
  "-- following created name is public --" printCompilerMessage
  publicAgain printStack _:;

  "-- public overload still participates in lookup --" printCompilerMessage
  helper printStack _:;

  "-- private overload also participates after module load --" printCompilerMessage
  hiddenHelper printStack _:;

  0
] "main" exportFunction

Expected Output During Compilation

-- following created name is public --
2
-- public overload still participates in lookup --
1
-- private overload also participates after module load --
3

See also