RomanYankovsky / DelphiAST

Abstract syntax tree builder for Delphi
Mozilla Public License 2.0
271 stars 116 forks source link

`as` in combination with inherited is broken #241

Open JBontes opened 6 years ago

JBontes commented 6 years ago

Take the following snippet from Data.DB:

Near Line 9800:

function TIDispatchField.GetValue: IDispatch;
begin
  Result := inherited GetValue as IDispatch;
end;

procedure TIDispatchField.SetValue(const Value: IDispatch);
begin
  inherited SetValue(Value as IUnknown);
end;

This yields the following output:

  <IMPLEMENTATION begin_line="6" begin_col="1" end_line="18" end_col="1">
    <METHOD begin_line="8" begin_col="1" end_line="13" end_col="1" kind="function">
   ....
            <EXPRESSION line="10" col="13">
              <INHERITED line="10" col="13">
                <IDENTIFIER line="10" col="23" name="GetValue"/>
                <AS line="10" col="32"/>  <<-- incorrect: `as` should have GetValue and IDispatch as children.
                <IDENTIFIER line="10" col="35" name="IDispatch"/>
              </INHERITED>
            </EXPRESSION>
   ...
    </METHOD>
    <METHOD begin_line="13" begin_col="1" end_line="18" end_col="1" kind="procedure">
 ....
        <INHERITED line="15" col="3">
          <CALL line="15" col="13">
            <CALL line="15" col="13">
              <IDENTIFIER line="15" col="13" name="SetValue"/>
              <EXPRESSIONS line="15" col="22">
                <EXPRESSION line="15" col="22">
                  <AS line="15" col="28">
                    <IDENTIFIER line="15" col="22" name="Value"/>
                    <IDENTIFIER line="15" col="31" name="IUnknown"/>
                  </AS>
                </EXPRESSION>
              </EXPRESSIONS>
            </CALL>
          </CALL>
        </INHERITED>
      </STATEMENTS>
    </METHOD>
  ....
  </IMPLEMENTATION>

In both cases the ntAs node should have 2 children: the left and right side of the equation.
The ntInherited node should only ever have 1 child: (something like) an expression.