[jira] Created: (BOO-1340) Invoking a closure on a method inside a generic type causes Bad IL and BadImageFormatException

Invoking a closure on a method inside a generic type causes Bad IL and BadImageFormatException
----------------------------------------------------------------------------------------------

                 Key: BOO-1340
                 URL: https://jira.codehaus.org/browse/BOO-1340
             Project: Boo
          Issue Type: Bug
          Components: Compiler
    Affects Versions: 0.9.4
         Environment: .net 3.5 and 4.0
            Reporter: Giovanni Bassi
            Priority: Minor

Attempting to call a regular method which references a generic parameter from it's type fails if you try to
pass a closure referencing the generic type.

{code:title=fails.boo|borderStyle=solid}
class Entity: 
	public Prop as string

class Repository[of T(Entity)]:
	def Get(p):
		Where({ p | p.Prop == p})
	def Where(predicate as System.Func[of T, bool]):
		pass
{code}

If you use a closure on an object where the generic parameter is already defined, it doesn't fail. This will pass:

{code:title=works.boo|borderStyle=solid}
class Entity: 
	public Prop as string

class Repository[of T(Entity)]:
	def Where(predicate as System.Func[of T, bool]):
		pass

Repository of Entity().Where({ p | p.Prop == p})
{code}

The result is bad IL. Here is the output of peverify.exe:
{code:borderStyle=solid}
Microsoft (R) .NET Framework PE Verifier.  Version  4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

[IL]: Error: [D:\Proj\src\Rabiscos\BooClassLibrary1\BooClassLibrary1\bin\Debug\B
ooClassLibrary1.exe : BooClassLibrary1.Repository`1[T]::Get]  [HRESULT 0x8007000
B] - An attempt was made to load a program with an incorrect format.

[IL]: Error: [D:\Proj\src\Rabiscos\BooClassLibrary1\BooClassLibrary1\bin\Debug\B
ooClassLibrary1.exe : BooClassLibrary1.Repository`1[T]::$Get$closure$1][offset 0
x00000001][found (unboxed) 'T'][expected ref 'BooClassLibrary1.Entity'] Unexpect
ed type on the stack.
[IL]: Error: [D:\Proj\src\Rabiscos\BooClassLibrary1\BooClassLibrary1\bin\Debug\B
ooClassLibrary1.exe : CompilerGenerated.__Class1$callable0$26_15__::Call][offset
 0x00000004] Unable to resolve token.
[IL]: Error: [D:\Proj\src\Rabiscos\BooClassLibrary1\BooClassLibrary1\bin\Debug\B
ooClassLibrary1.exe : CompilerGenerated.$adaptor$__Class1$callable0$26_15__$Func
$0::Invoke]  [HRESULT 0x8007000B] - An attempt was made to load a program with a
n incorrect format.

[IL]: Error: [D:\Proj\src\Rabiscos\BooClassLibrary1\BooClassLibrary1\bin\Debug\B
ooClassLibrary1.exe : CompilerGenerated.$adaptor$__Class1$callable0$26_15__$Func
$0::Adapt]  [HRESULT 0x8007000B] - An attempt was made to load a program with an
 incorrect format.

5 Error(s) Verifying BooClassLibrary1.exe
{code}

Running we get a BadImageFormatException:
{code:borderStyle=solid}
Unhandled Exception: System.BadImageFormatException: An attempt was made to load
 a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
{code}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Gmane