Exception with KClass<T>.createInstance(): java.lang.IllegalArgumentException: Callable expects 2 arguments, but 0 were provided

hi, i seem to have a problem with reflection
im making my custom language, kotlin acts as an interpreter (my language is not compiled ||yet||)
so this is the error when im trying to create an instance of a class created from within my language (from repl):

java.lang.IllegalArgumentException: Callable expects 2 arguments, but 0 were provided.
	at kotlin.reflect.jvm.internal.calls.Caller$DefaultImpls.checkArguments(Caller.kt:20)
	at kotlin.reflect.jvm.internal.calls.CallerImpl.checkArguments(CallerImpl.kt:15)
	at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:40)
	at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108)
	at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:159)
	at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112)
	at kotlin.reflect.full.KClasses.createInstance(KClasses.kt:280)
	at stdlib.libstruct.functions.FunctionOverload$Companion$constructor$1.call(FunctionOverload.kt:44)
	at stdlib.libstruct.functions.FunctionWithOverloads.callWithValues(FunctionOverload.kt:130)
	at stdlib.libstruct.functions.FunctionWithOverloads.callWithExpressions(FunctionOverload.kt:95)
	at parser.ast.expressions.FunctionCallExpression.eval(FunctionCallExpression.kt:47)
	at parser.ast.statements.VariableDefineStatement.execute(VariableDefineStatement.kt:15)
	at parser.ast.statements.Statements.execute(Statements.kt:16)
	at ProgramKt.main(Program.kt:195)

I create an instance with KClass.createInstance() (type::class.createInstance) where type is a class container object (class that contains constructors, members, etc)

but when i create classes in Kotlin (like a builtin), everything is OK
if you wanna try for yourself and see the problem here are the sources of an interpreter: GitHub - Craftist/Baila: My umpteenth attempt at creating a programming language, most advanced so far
just clone it, compile, launch (you will be greeted with a REPL) and try to type these in:

var t = TestClass() (TestClass is a builtin added in Baila/NameTable.kt at master · Craftist/Baila · GitHub)
no errors will be produced

:debug (just type this into a REPL, this will enable stack traces in console. if you dont do this you will just get an exception type and message)

class OtherTest { } will create a new user-defined class
var t2 = OtherTest() will throw an exception and you can see where it has led

the code that actually creates an instance of a class is at Baila/FunctionOverload.kt at master · Craftist/Baila · GitHub
from there you can go up the stacktrace and see where the error is at

i know i did a very wrong thing at Baila/ClassDefineStatement.kt at master · Craftist/Baila · GitHub and i don’t know if the problem is in local classes or not. it probably is… but is it a feature, a design limitation, or is it a bug? should it be fixed or maybe the description changed? have i forgotten to pass something? like i can read, i understand that it expects 2 parameters in somewhere while i have zero, but i debugged that code, when i instantiante builtin classes (like TestClass) everything is fine.

Hi, this code is really very complicated and it is hard to say, what is happening there. It is quite weird to me that in FunctionOverload.kt:44 you have an instance of TypeContainer and you initialize another one of the same subtype. If TypeContainer is some kind of a type token then why to “copy” it? Did you mean to create an instance of object that is represented as TypeContainer? TypeContainer has createInstance() function, but this is not what you invoke here.

Add some logs around this line to see what is the exact value of the type variable. It seems it is some class that requires 2 params in its constructor and you don’t provide any.