Boo

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

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 0.9.4
  • Fix Version/s: None
  • Component/s: Compiler
  • Labels:
    None
  • Environment:
    .net 3.5 and 4.0
  • Number of attachments :
    0

Description

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.

fails.boo
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

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

works.boo
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})

The result is bad IL. Here is the output of peverify.exe:

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

Running we get a BadImageFormatException:

Unhandled Exception: System.BadImageFormatException: An attempt was made to load
 a program with an incorrect format. (Exception from HRESULT: 0x8007000B)

Activity

Hide
Maksym Trushyn added a comment -

I tested the similar scenario after applying my patch (https://github.com/bamboo/boo/pull/18)
The following scenario worked for me:

"""
True
False
"""
import System
import System.Collections.Generic
import System.Linq.Enumerable

class Entity:
public Prop as string

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

Repository of Entity().Get(Entity())

I think that this issue is the same as BOO-854.

Show
Maksym Trushyn added a comment - I tested the similar scenario after applying my patch (https://github.com/bamboo/boo/pull/18) The following scenario worked for me: """ True False """ import System import System.Collections.Generic import System.Linq.Enumerable class Entity: public Prop as string class Repository[of T(Entity)]: def Get(p): Where({ p | p.Prop == "333"}) def Where(predicate as System.Func[of T, bool]): print predicate(Entity(Prop:"333")) print predicate(Entity(Prop:"444")) Repository of Entity().Get(Entity()) I think that this issue is the same as BOO-854.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: