Project

General

Profile

Bug #749

IsDefined does not follow reference to undefined optional param

Added by John Abbott over 8 years ago. Updated over 8 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Parser/Interpreter
Target version:
Start date:
27 Jul 2015
Due date:
% Done:

0%

Estimated time:
Spent time:

Description

The pseudo-function IsDefined has weird semantics.

Consider this example:

define IsVerbose(ref VerbFlag)
  if not(IsDefined(VerbFlag)) then return false; endif;
  if VerbFlag <> "verbose" then error("expected \"verbose\""); endif;
  return true;
enddefine;

define MyFunc(X, opt OptArg)
  VerboseFlag := IsVerbose(ref OptArg);
  ...
enddefine;

If MyFunc is called with 1 arg then inside MyFunc the parameter OptArg is not defined, but when inside IsVerbose the call to IsDefined(VerbFlag) returns true.

JAA thinks that IsDefined should follow references -- this would lead to the simple criterion that if IsDefined(V) produces true then the variable V actually has a value.

History

#1 Updated by John Abbott over 8 years ago

Anna points out that there is a workaround:

define IsDefd(ref V)
  try
    junk := V;
  uponerror err do
    return false;
  endtry;
  return true;
enddefine;

Not pretty :-(
Surely IsDefined should already be doing exactly this?!?

#2 Updated by John Abbott over 8 years ago

The relevant source code seems to be at Interpreter.C:3403

Update: Mmmm, uncommented code looks scary :-(

#3 Updated by John Abbott over 8 years ago

  • Subject changed from IsDefined does not follow references to IsDefined does not follow reference to undefined optional param

JAA is having trouble understanding what the code does/should do. Can Giovanni help?

Also available in: Atom PDF