Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi Prism/Compiler    [ Add a report in this area ]  
Report #:  93522   Status: Open
Compiler generates invalid IL code for colon operator (Collection)
Project:  Embarcadero Prism Build #:  4.0.27.843
Version:    14.1 Submitted By:   Hugo Logmans
Report Type:  Minor failure / Design problem Date Reported:  5/3/2011 3:20:54 AM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   283134
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: 1
Description
The code below generates an exception (invalid program), debugging into code is not possible because the exception is thrown before entering the code:

var EmptyItems := new ObservableCollection<TIBSpecLine>(FData.Select(f -> f).Where(f -> f.IsEmpty = True));
EmptyItems[0]:Soort := 'Hoihoi'; // <- this line

If I use . instead of : it works fine, but I want to use : because the collection might be empty.

Using EmptyItems.First:Soort also does not work.

I tried to create a test project, but then it worked fine, so it might be related to the objects used.

I use the : operator quite often, this is the first time I encounter problems with it. And the special case is it is now used on a collection.


Exception:

System.InvalidProgramException was unhandled
  Message=Common Language Runtime detected an invalid program.
  Source=SduTaxbox
  StackTrace:
       at SduTaxbox.IBSpec`1.CheckEmptyLine(Boolean aEnsureThereIsOne)
       at SduTaxbox.IBGroup`1.CheckEmptyLine(Boolean aEnsureThereIsOne) in Z:\Work\Edb\SduTaxbox\SduTaxbox\SduTaxbox\IBData.pas:line 356
       at SduTaxbox.IB_Group_Loon..ctor() in Z:\Work\Edb\SduTaxbox\SduTaxbox\SduTaxbox\IBDataCommon.pas:line 395
       at SduTaxbox.IBAangifte..ctor() in Z:\Work\Edb\SduTaxbox\SduTaxbox\SduTaxbox\IBAangifte.xaml.pas:line 25
       at SduTaxbox.MainWindow.btnStartIB_Click(Object sender, RoutedEventArgs e) in Z:\Work\Edb\SduTaxbox\SduTaxbox\SduTaxbox\MainWindow.xaml.pas:line 86
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.Controls.Button.OnClick()
       at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
       at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
       at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
       at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
       at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args)
       at System.Windows.Input.InputManager.ProcessStagingArea()
       at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
       at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
       at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
       at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean&amp; handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG&amp; msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run()
       at SduTaxbox.App.Main()
  InnerException:
Steps to Reproduce:
Added by Sysop
<<<<<<
Please see comments of QC report for more details.
>>>>>>
Workarounds
Added by Sysop
<<<<
Workaround:
Just use manual nil-check and normal . operator.
>>>>
Attachment
None
Comments

Hugo Logmans at 5/3/2011 3:26:36 AM -
Only the setter has this problem. This line works:

    if FData.First:Soort = '' then FData.First.Soort := firstLabel;

(notice the first : in the getter).

FYI: 'Soort' has no custom getter/setter

  IBSpecLine = public partial class
  protected
    method get_IsEmpty : Boolean; virtual;
  public
    constructor; empty;
    constructor(aKey : String);

    [BrowsableAttribute(false)]
    property Soort : String := ''; // moet voor eerste regel gevuld zijn, voor de rest leeg
    [BrowsableAttribute(false)]
    property LineID : String;
    [BrowsableAttribute(false)]
    property IsEmpty : Boolean read get_IsEmpty; virtual;

  end;

Hugo Logmans at 5/3/2011 3:30:03 AM -
Hmm, after editing the report 'Steps to reproduce' and 'Workaround' are gone...

Workaround:
Just use manual nil-check and normal . operator.

Tomohiro Takahashi at 5/3/2011 7:15:33 AM -
If you update your report, please use Windows Native QC Client. The standalone client is available at this URL.
http://qc.codegear.com/qualitycentral.zip

Hugo Logmans at 5/4/2011 5:56:31 AM -
I used a decompiler (JustDecompile) to see the difference in code:

Using :

if ((!this.FData.First() ? null : &current.Soort) == "")

{


current = !this.FData.First();


&current.Soort = soort;


goto L_0193;

}
L_0193:

Using .

if ((!this.FData.First() ? null : &current.Soort) == "")

{


current = this.FData.First();


&current.Soort = soort;

}

So the changes are:
- using a GOTO that doesn't seem a problem to me
- Adding a ! before this.FData.First() on the 3rd line.

But maybe the decompiler is not working correctly? My test console project generates this (but my C knowledge may be too low)...

class method ConsoleApp.Main(args: array of string);
begin
  var items := new System.Collections.ObjectModel.ObservableCollection<SmallClass>;
  var c := new SmallClass;
  c.Soort := 'hhh';
  items.Add(c);
  items:First:Soort := 'Hello'; // <- Now i use : twice and the decompiled code is strange?
  // add your own code here
  Console.WriteLine('Hello World.');
end;

decompiles to:

public static void Main(string[] args)
{

ObservableCollection<SmallClass> observableCollection = new ObservableCollection<SmallClass>();

SmallClass smallClass = new SmallClass();

smallClass.Soort = "hhh";

observableCollection.Add(smallClass);

observableCollection == null.First();

observableCollection == null.Soort = "Hello";

observableCollection;

Console.WriteLine("Hello World.");
}

Hugo Logmans at 5/13/2011 1:09:21 AM -
I think the severity of this problem must be raised to 2. The colon operator does not work anymore in many cases. I do not get the Invalid code-exception for the code below, but the : simply does not work.

Example code:

namespace ConsoleApplication1;

interface

uses System.Text, System.Collections.ObjectModel;

type
  ConsoleApp = class
  public
    class method Main(args: array of string);
    class property test : zzz;
  end;


type
  zzz = public class
  public
    property items : ObservableCollection<Int64> := new ObservableCollection<Int64>;
  end;
implementation

class method ConsoleApp.Main(args: array of string);
begin

  test:items:Clear; // this line works
  test:items.Clear; // get System.NullReferenceException here

  // add your own code here
  Console.WriteLine('Hello World.');
end;

end.

If I add 'If test <> nil then ' before the second test-line the exception does not occur.

Server Response from: ETNACODE01