1
mirror of https://github.com/revanced/revanced-patcher synced 2025-09-06 16:38:50 +02:00

Compare commits

..

3 Commits

Author SHA1 Message Date
semantic-release-bot
8f78f85e4a chore(release): 4.2.2 [skip ci]
## [4.2.2](https://github.com/revanced/revanced-patcher/compare/v4.2.1...v4.2.2) (2022-09-08)

### Bug Fixes

* invalid type propagation in options ([b873228](b873228ef0)), closes [#98](https://github.com/revanced/revanced-patcher/issues/98)
2022-09-08 14:50:38 +00:00
Sculas
0be2677519 Merge remote-tracking branch 'origin/main' into main 2022-09-08 16:49:26 +02:00
Sculas
b873228ef0 fix: invalid type propagation in options
Fixes #98
2022-09-08 16:49:06 +02:00
6 changed files with 37 additions and 10 deletions

View File

@@ -1,3 +1,10 @@
## [4.2.2](https://github.com/revanced/revanced-patcher/compare/v4.2.1...v4.2.2) (2022-09-08)
### Bug Fixes
* invalid type propagation in options ([b873228](https://github.com/revanced/revanced-patcher/commit/b873228ef0a9e6e431a4278c979caa5fcc508e0d)), closes [#98](https://github.com/revanced/revanced-patcher/issues/98)
## [4.2.1](https://github.com/revanced/revanced-patcher/compare/v4.2.0...v4.2.1) (2022-09-08)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official
version = 4.2.1
version = 4.2.2

View File

@@ -101,11 +101,13 @@ sealed class PatchOption<T>(
* Gets the value of the option.
* Please note that using the wrong value type results in a runtime error.
*/
inline operator fun <reified V> getValue(thisRef: Any?, property: KProperty<*>) =
value as? V ?: throw InvalidTypeException(
inline operator fun <reified V> getValue(thisRef: Any?, property: KProperty<*>): V? {
if (value !is V?) throw InvalidTypeException(
V::class.java.canonicalName,
value?.let { it::class.java.canonicalName } ?: "null"
)
return value as? V?
}
/**
* Gets the value of the option.

View File

@@ -0,0 +1,18 @@
package app.revanced.patcher.issues
import app.revanced.patcher.patch.PatchOption
import org.junit.jupiter.api.Test
import kotlin.test.assertNull
internal class Issue98 {
companion object {
var key1: String? by PatchOption.StringOption(
"key1", null, "title", "description"
)
}
@Test
fun `should infer nullable type correctly`() {
assertNull(key1)
}
}

View File

@@ -48,7 +48,7 @@ internal class PatchOptionsTest {
@Test
fun `should return a different value when changed`() {
var value: String by options["key1"]
var value: String? by options["key1"]
val current = value + "" // force a copy
value = "Hello, world!"
assertNotEquals(current, value)

View File

@@ -171,32 +171,32 @@ class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
}
companion object : OptionsContainer() {
private var key1: String by option(
private var key1: String? by option(
PatchOption.StringOption(
"key1", "default", "title", "description", true
)
)
private var key2: Boolean by option(
private var key2: Boolean? by option(
PatchOption.BooleanOption(
"key2", true, "title", "description" // required defaults to false
)
)
private var key3: String by option(
private var key3: String? by option(
PatchOption.StringListOption(
"key3", "TEST", listOf("TEST", "TEST1", "TEST2"), "title", "description"
)
)
private var key4: Int by option(
private var key4: Int? by option(
PatchOption.IntListOption(
"key4", 1, listOf(1, 2, 3), "title", "description"
)
)
private var key5: Path by option(
private var key5: Path? by option(
PatchOption.PathOption(
"key5", File("test.txt").toPath(), "title", "description"
)
)
private var key6: String by option(
private var key6: String? by option(
PatchOption.StringOption(
"key6", null, "title", "description", true
)