Limit scheme property extension to MutableMeta to avoid override resolution ambiguity

This commit is contained in:
Alexander Nozik 2025-02-23 10:12:55 +03:00
parent 3acbaffecb
commit 671d2b2493
5 changed files with 16 additions and 18 deletions
CHANGELOG.mdbuild.gradle.kts
dataforge-io
dataforge-meta/src
commonMain/kotlin/space/kscience/dataforge/meta
commonTest/kotlin/space/kscience/dataforge/meta

@ -15,6 +15,7 @@
### Fixed
- Incorrect work of `MetaWithDefault::getValue`
- Incorrect work of scheme delegate
### Security

@ -9,7 +9,7 @@ plugins {
allprojects {
group = "space.kscience"
version = "0.10.1-dev"
version = "0.10.1-dev-1"
}
subprojects {

@ -4,8 +4,6 @@ plugins {
description = "IO module"
val ioVersion = "0.6.0"
kscience {
jvm()
js()
@ -17,8 +15,8 @@ kscience {
}
dependencies {
api(projects.dataforgeContext)
api("org.jetbrains.kotlinx:kotlinx-io-core:$ioVersion")
api("org.jetbrains.kotlinx:kotlinx-io-bytestring:$ioVersion")
api(spclibs.kotlinx.io.core)
api(spclibs.kotlinx.io.bytestring)
}
}

@ -219,15 +219,15 @@ public fun <T : Scheme> Configurable.updateWith(
/**
* A delegate that uses a [MetaReader] to wrap a child of this provider
* A delegate that uses a [SchemeSpec] to wrap a child of this provider
*/
public fun <T : Scheme> MutableMetaProvider.scheme(
public fun <T : Scheme> MutableMeta.scheme(
spec: SchemeSpec<T>,
key: Name? = null,
): ReadWriteProperty<Any?, T> = object : ReadWriteProperty<Any?, T> {
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
val name = key ?: property.name.asName()
val node = get(name) ?: MutableMeta().also { set(name, it) }
val node = getOrCreate(name)
return spec.write(node)
}
@ -243,7 +243,7 @@ public fun <T : Scheme> Scheme.scheme(
): ReadWriteProperty<Any?, T> = meta.scheme(spec, key)
/**
* A delegate that uses a [MetaReader] to wrap a child of this provider.
* A delegate that uses a [SchemeSpec] to wrap a child of this provider.
* Returns null if meta with given name does not exist.
*/
public fun <T : Scheme> MutableMeta.schemeOrNull(

@ -26,18 +26,17 @@ internal class TestScheme : Scheme() {
companion object : SchemeSpec<TestScheme>(::TestScheme)
}
private class SchemeWithInit: Scheme(){
private class SchemeWithInit : Scheme() {
init {
set("initial", "initialValue")
}
var initial by string()
companion object: SchemeSpec<SchemeWithInit>(::SchemeWithInit)
companion object : SchemeSpec<SchemeWithInit>(::SchemeWithInit)
}
class SpecificationTest {
// @Test
@ -126,11 +125,11 @@ class SpecificationTest {
}
@Test
fun testListSubscription(){
fun testListSubscription() {
val scheme = TestScheme.empty()
var value: Value? = null
scheme.v = ListValue(0.0,0.0,0.0)
scheme.useProperty(TestScheme::v){
scheme.v = ListValue(0.0, 0.0, 0.0)
scheme.useProperty(TestScheme::v) {
value = it
}
scheme.v = ListValue(1.0, 2.0, 3.0)
@ -138,17 +137,17 @@ class SpecificationTest {
}
@Test
fun testSubScheme(){
fun testSubScheme() {
val scheme = TestScheme.empty()
scheme.sub.subValue = "aaa"
assertEquals("aaa",scheme.sub.subValue)
assertEquals("aaa", scheme.sub.subValue)
}
@Test
fun testSchemeWithInit(){
fun testSchemeWithInit() {
val scheme = SchemeWithInit()
assertEquals("initialValue", scheme.initial)
scheme.initial = "none"