Improved instance method resolution logic and added test for Decimal overloading.
This commit is contained in:
parent
286ec30422
commit
cdd48ec871
@ -1180,8 +1180,11 @@ open class ObjClass(
|
||||
scope: Scope, name: String, args: Arguments,
|
||||
onNotFoundResult: (suspend () -> Obj?)?
|
||||
): Obj {
|
||||
getInstanceMemberOrNull(name)?.let { rec ->
|
||||
val decl = rec.declaringClass ?: findDeclaringClassOf(name) ?: this
|
||||
classScope?.objects?.get(name)?.let { rec ->
|
||||
val decl = rec.declaringClass ?: this
|
||||
if (!rec.visibility.isPublic) {
|
||||
return super.invokeInstanceMethod(scope, name, args, onNotFoundResult)
|
||||
}
|
||||
if (rec.type == ObjRecord.Type.Delegated) {
|
||||
val del = rec.delegate ?: scope.raiseError("Internal error: delegated member $name has no delegate")
|
||||
val allArgs = (listOf(this, ObjString(name)) + args.list).toTypedArray()
|
||||
|
||||
@ -295,4 +295,17 @@ class DecimalModuleTest {
|
||||
|
||||
assertEquals(2, ex.pos.line)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOverloading() = runTest {
|
||||
eval("""
|
||||
import lyng.decimal
|
||||
assert( 1.d is Decimal )
|
||||
assertEquals(Decimal, abs(1.d)::class)
|
||||
// here the inference must work:
|
||||
val t = abs(-10.d)
|
||||
assert(t is Decimal)
|
||||
assertEquals(10,t)
|
||||
""".trimIndent())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user