IronLanguages / main

Work for this repo has moved to https://github.com/IronLanguages/ironpython2
1.16k stars 350 forks source link

HAPI : ObjectOperations : RemoveMember throws System.MissingMemberException when called for objects with an existing member #712

Open ironpythonbot opened 9 years ago

ironpythonbot commented 9 years ago

Add Description

Repro steps==========

public void TestObjectOperations_RemoveMember(){

string lookupClassVarName = "FooClass";
string lookupMemberName = "inc";
string testSrc = "class FooClass:\n"
               + "    def inc(self, x):\n"
               + "        return x+1;";

ScriptRuntime runtime = ScriptRuntime.Create();
ScriptEngine testEng = runtime.GetEngine("py");
ScriptScope scope = testEng.CreateScope();
scope.Execute(testSrc);
object objectVar = scope.GetVariable(lookupClassVarName);
object fooClass = (testEng.Operations).Call(objectVar); // create new FooClass
// Verify that the member function exists
Assert.IsTrue((testEng.Operations).ContainsMember(fooClass, lookupMemberName));
// Remove the member function
Assert.IsTrue((testEng.Operations).RemoveMember(fooClass, lookupMemberName));
// Verify that the member does not exists anymore
Assert.IsFalse((testEng.Operations).ContainsMember(fooClass, lookupMemberName));

}
Expected Behavior ==============Successfully removes "inc" member.
Actual Behavior============Raises 'MissingMemberException' on the RemoveMember(...) call

This seems to be a python specific issue.

the part where RemoveMember does not work is correct. I tried same scenario in Python console and it did not delete inc method either.
the wrong part is throwing exeption where it should just return false.

--NEW REPRO UPDATED FOR HAPI

CHANGES---------------------------------------------

csc /reference:D:\vsl\Merlin\Main\Bin\Debug\Microsoft.Dynamic.dll /reference:D:\vsl\Merlin\Main\Bin\Debug\Microsoft.Scripting.Core.dll /reference:D:\vsl\Merlin\Main\Bin\Debug\Microsoft.Scripting.dll /reference:D:\vsl\Merlin\Main\Bin\Debug\IronPython.dll blah.cs

...

blah.exe
True

Unhandled Exception: System.MissingMemberException: inc is not a valid attribute
at IronPython.Runtime.Types.OldInstance.DeleteCustomMember(CodeContext context, String name) in d:\vsl\Merlin\Main\La
nguages\IronPython\IronPython\Runtime\Types\OldInstance.cs:line 590
at IronPython.Runtime.Operations.PythonOps.OldInstanceDeleteCustomMember(CodeC ontext context, OldInstance self, Strin
g name) in d:\vsl\Merlin\Main\Languages\IronPython\IronPython\Runtime\Operatio ns\PythonOps.cs:line 3248
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid1[T0](CallSite site, T0 arg0) in d:\vsl\ndp\fx\src\Core\Microso
ft\Scripting\Actions\UpdateDelegates.Generated.cs:line 1511
at Microsoft.Scripting.Runtime.DynamicOperations.RemoveMember(Object obj, String name, Boolean ignoreCase) in d:\vsl\
Merlin\Main\Runtime\Microsoft.Scripting\Runtime\DynamicOperations.cs:line 207
at Microsoft.Scripting.Runtime.DynamicOperations.RemoveMember(Object obj, String name) in d:\vsl\Merlin\Main\Runtime\
Microsoft.Scripting\Runtime\DynamicOperations.cs:line 141
at Microsoft.Scripting.Hosting.ObjectOperations.RemoveMember(Object obj, String name) in d:\vsl\Merlin\Main\Runtime\M
icrosoft.Scripting\Hosting\ObjectOperations.cs:line 135
at Blah.Main()

Work Item Details

Original CodePlex Issue: Issue 24068 Status: Active Reason Closed: Unassigned Assigned to: Unassigned Reported on: Jul 28, 2009 at 1:00 AM Reported by: dfugate Updated on: Feb 22, 2013 at 2:11 AM Updated by: jdhardy Custom value: Reported internally at Microsoft. Test: HostingTest\ObjectOperationsTest.cs CreatedDate: 7/23/2008 NewInternalID: 478257 AreaPath: IronPython

Plaintext Attachments

CodePlex Issue #24068 Plain Text Attachments

ironpythonbot commented 9 years ago

On 2009-11-24 09:16:47 UTC, dfugate commented:

Not fixed. The test case is a negative scenario that I wouldn't expect to work, but also we should not be throwing "System.MissingMemberException: inc is not a valid attribute". I'll post an updated repro later.