Invalid IL code exception when calling method

I’m trying to find out prime numbers in my script, but when I call my function for that, I get a strange error: InvalidProgramException: Invalid IL code in RSA:isPrim (int): IL_0057: ldloc.0
Code:

def genPrim (start as int, max as int):
	rdom as int
	k = 2
	while true:
		rdom = Random.Range(start, max)
		if self.isPrim(rdom):
			break
	return rdom
	
def isPrim (zahl as int):
	finished as bool
	if zahl <= 1:
		finished = true
	if not finished:
		while k**2 <= zahl:
			if zahl % k == 0:
				finished = true
			k += 1       	
	return not finished

I checked everything and I just can’t find anything wrong :confused:

I still don’t really have an idea of the error, but for some reason it was gone, when I changed the type of the variable “k” from int to double.

Invalid IL code

Seems to be a bug in the IL converter, please submit a bug report with the sample project that causes that error: