Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange behavior when instantiating a class in an anonymous function #1117

Closed
FibonacciFox opened this issue Jun 27, 2023 · 4 comments
Closed

Comments

@FibonacciFox
Copy link

When creating an instance of the System\Uri class; in an anonymous function, the program crashes with an error:

Unhandled exception. System.InvalidOperationException: CostOf.ToUriCreationOptions(Pchp.Core.PhpValue) was not resolved.
   at Pchp.Core.Dynamic.Cache.GetMethod(Type type, String name, Type[] ptypes)
   at Pchp.Core.Dynamic.ConvertExpression.BindCostFromValue(Expression arg, Type target)
   at Pchp.Core.Dynamic.ConvertExpression.BindCostFromValue(Expression arg, Type target)
   at Pchp.Core.Dynamic.ConvertExpression.BindCost(Expression arg, Type target)
   at Pchp.Core.Dynamic.OverloadBinder.ArgumentsBinder.BindCostOf(Int32 srcarg, Type ptype, Boolean ismandatory, Boolean ignorecost)
   at Pchp.Core.Dynamic.OverloadBinder.BindCostOf(MethodBase method, ArgumentsBinder args, BitArray costofargs, ConversionCost& minCost)
   at Pchp.Core.Dynamic.OverloadBinder.BindOverloadCall(Type treturn, Expression target, MethodBase[]& methods, Expression ctx, ArgumentsBinder args, Boolean isStaticCallSyntax, Object lateStaticType)
   at Pchp.Core.Dynamic.OverloadBinder.BindOverloadCall(Type treturn, Expression target, MethodBase[] methods, Expression ctx, Expression argsarray, Boolean isStaticCallSyntax, Object lateStaticType)
   at Pchp.Core.Dynamic.BinderHelpers.BindToCreator(Type type, ConstructorInfo[] ctors)
   at Pchp.Core.Reflection.PhpTypeInfo.BuildCreator()
   at Pchp.Core.Reflection.PhpTypeInfo.get_Creator()
   at Pchp.Core.Reflection.PhpTypeInfo.ResolveCreator(Type caller)
   at Pchp.Core.Context.Create[T](RuntimeTypeHandle caller, PhpValue[] arguments)
   at <Root>src/Application/Forms.MainWindow_php.anonymous@function(Closure <closure>, PhpValue ThisClass, PhpValue hello, PhpValue sender, PhpValue e) in C:\Users\Albina\Desktop\NewAvaloniaPeachpie\NewAvaloniaPeachpie\Application\s
rc\Application\Forms\MainWindow.php:line 34
   at anonymous@function#1(Closure, Context, PhpValue[])
   at Pchp.Core.Reflection.RoutineInfo.Invoke(Context ctx, Object target, PhpValue[] arguments)
   at Pchp.Core.Reflection.RoutineInfo.Pchp.Core.IPhpCallable.Invoke(Context ctx, PhpValue[] arguments)
   at Closure.__invoke(PhpValue[] parameters)
   at NewAvaloniaPeachpie.Experimental.Events.<>c__DisplayClass0_0.<On>b__0(Object _, EventArgs e) in C:\Users\Albina\Desktop\NewAvaloniaPeachpie\NewAvaloniaPeachpie\NewAvaloniaPeachpie\Experimental\Events.cs:line 16
   at Avalonia.Interactivity.Interactive.<AddHandler>g__InvokeAdapter|4_0[TEventArgs](Delegate baseHandler, Object sender, RoutedEventArgs args) in /_/src/Avalonia.Base/Interactivity/Interactive.cs:line 64
   at Avalonia.Interactivity.Interactive.<>c__4`1.<AddHandler>b__4_1(Delegate baseHandler, Object sender, RoutedEventArgs args) in /_/src/Avalonia.Base/Interactivity/Interactive.cs:line 70
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/EventRoute.cs:line 118
   at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/EventRoute.cs:line 79
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/Interactive.cs:line 126
   at Avalonia.Controls.Button.OnClick() in /_/src/Avalonia.Controls/Button.cs:line 344
   at Avalonia.Controls.Button.OnPointerReleased(PointerReleasedEventArgs e) in /_/src/Avalonia.Controls/Button.cs:line 416
   at Avalonia.Input.InputElement.<>c.<.cctor>b__32_9(InputElement x, PointerReleasedEventArgs e) in /_/src/Avalonia.Base/Input/InputElement.cs:line 225
   at Avalonia.Reactive.LightweightObservableBase`1.PublishNext(T value) in /_/src/Avalonia.Base/Reactive/LightweightObservableBase.cs:line 149
   at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/EventRoute.cs:line 118
   at Avalonia.Interactivity.EventRoute.RaiseEvent(Interactive source, RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/EventRoute.cs:line 79
   at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) in /_/src/Avalonia.Base/Interactivity/Interactive.cs:line 126
   at Avalonia.Input.MouseDevice.MouseUp(IMouseDevice device, UInt64 timestamp, IInputRoot root, Point p, PointerPointProperties props, KeyModifiers inputModifiers, IInputElement hitTest) in /_/src/Avalonia.Base/Input/MouseDevice.cs
:line 200
   at Avalonia.Input.MouseDevice.ProcessRawEvent(RawPointerEventArgs e) in /_/src/Avalonia.Base/Input/MouseDevice.cs:line 58
   at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e) in /_/src/Avalonia.Base/Input/InputManager.cs:line 37
   at Avalonia.Controls.TopLevel.HandleInput(RawInputEventArgs e) in /_/src/Avalonia.Controls/TopLevel.cs:line 739
   at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs:line 812
   at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs:line 26
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken) in /_/src/Windows/Avalonia.Win32/Win32DispatcherImpl.cs:line 111
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl) in /_/src/Avalonia.Base/Threading/DispatcherFrame.cs:line 117
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame) in /_/src/Avalonia.Base/Threading/Dispatcher.MainLoop.cs:line 53
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.MainLoop.cs:line 80
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 127
   at NewAvaloniaPeachpie.Platform.Application..ctor(Closure closure, String[] args) in C:\Users\Albina\Desktop\NewAvaloniaPeachpie\NewAvaloniaPeachpie\NewAvaloniaPeachpie\Platform\Application.cs:line 28
   at <Root>.ApplicationDesktop_php.<Main>(Context <ctx>, PhpArray <locals>, Object this, RuntimeTypeHandle <self>) in C:\Users\Albina\Desktop\NewAvaloniaPeachpie\NewAvaloniaPeachpie\ApplicationDesktop\ApplicationDesktop.php:line 8
   at <Script>.Main(String[] args) 

But when declared:
$uri = new Uri('avares://Application/src/Application/Forms/MyWindow.axaml');
Anywhere else in the code, everything works.
It seems to me that such behavior should not be.

Link to the project with this exception: https://github.com/FibonacciFox/NewAvaloniaPeachpie

@FibonacciFox
Copy link
Author

I have a suspicion that the problem is in the Closure.

@jakubmisek
Copy link
Member

Hi @FibonacciFox and thank you for reporting the issue.

For some reason, it compiles new Uri(..) differently than outside the closure. I'll have to debug it for more details.

@jakubmisek
Copy link
Member

thank you @FibonacciFox , there were a few issues with this case, fixed now.

@FibonacciFox
Copy link
Author

FibonacciFox commented Aug 28, 2023

thank you @FibonacciFox , there were a few issues with this case, fixed now.

thank you @jakubmisek !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants