Comments (3)
I don't get a compilation error, but I do see a test case based on it passing on the Swift side and failing on the Kotlin side:
class MutatingEnumTests: XCTestCase {
enum Count {
case one
case two
case three
mutating func reset() {
self = .one
}
}
func testMutatingEnum() throws {
var b = Count.three
XCTAssertEqual(Count.three, b)
b.reset()
XCTAssertEqual(Count.one, b)
}
}
This transpiles into MutatingEnumTests.kt
:
internal class MutatingEnumTests: XCTestCase {
internal enum class Count {
one,
two,
three;
internal fun reset(): Unit = assignfrom(MutatingEnumTests.Count.one)
private fun assignfrom(target: MutatingEnumTests.Count) = Unit
}
@Test
internal fun testMutatingEnum() {
var b = Count.three
XCTAssertEqual(Count.three, b)
b.reset()
XCTAssertEqual(Count.one, b)
}
}
This is a transpiler bug, so I'll move this issue over to the skip repo. Thanks for reporting it!
from skip.
For completeness, I'll point out that the equivalent test does pass with structs:
@available(macOS 13, *)
final class MutatingStructTests: XCTestCase {
struct Count : Equatable {
private let count: Int
static let one = Count(count: 1)
static let two = Count(count: 2)
static let three = Count(count: 3)
mutating func reset() {
self = .one
}
}
func testMutatingStruct() throws {
var b = Count.three
XCTAssertEqual(Count.three, b)
b.reset()
XCTAssertEqual(Count.one, b)
}
}
which transpiles to:
internal class MutatingStructTests: XCTestCase {
internal class Count: MutableStruct {
private var count: Int
internal fun reset() {
willmutate()
try {
assignfrom(MutatingStructTests.Count.one)
} finally {
didmutate()
}
}
private constructor(count: Int) {
this.count = count
}
override var supdate: ((Any) -> Unit)? = null
override var smutatingcount = 0
override fun scopy(): MutableStruct = MutatingStructTests.Count(count)
private fun assignfrom(target: MutatingStructTests.Count) {
this.count = target.count
}
override fun equals(other: Any?): Boolean {
if (other !is MutatingStructTests.Count) return false
return count == other.count
}
companion object {
internal val one = Count(count = 1)
internal val two = Count(count = 2)
internal val three = Count(count = 3)
}
}
@Test
internal fun testMutatingStruct() {
var b = Count.three.sref()
XCTAssertEqual(Count.three, b)
b.reset()
XCTAssertEqual(Count.one, b)
}
}
So the issue is specific to enums, not to all value types.
from skip.
We're not going to be able to support this and still use Kotlin enums. I added detection and an error message to that effect to the transpiler.
from skip.
Related Issues (20)
- NavigationStack adds "padding" to android top screen HOT 4
- Java version: error executing java HOT 5
- Command PhaseScriptExecution failed with a nonzero exit code HOT 21
- Request: RealmSwift demo HOT 3
- WebSocket APIs for Skip HOT 2
- Small BUG: 'skip checkup' and 'skip doctor' cant find JetBrains installed Android Studio HOT 3
- Requires license in free mode HOT 2
- skip checkup passes, but I'm unable to compile HelloSkip HOT 8
- ERROR: JAVA_HOME is set to an invalid directory: /opt/homebrew/opt/java HOT 1
- Unable to update iOS Deployment Target (minimum iOS version supported) HOT 2
- Type mismatch when working with ForEach with generics HOT 4
- Skip created a corrupted emulator in ADB HOT 2
- Locale.current.currency?.identifier: Skip is unable to determine the owning type... HOT 3
- Extensions on Array that are not referenced in the compile unit may fail to `import skip.lib.Array`, thus resulting in the wrong Array type being used HOT 2
- Fail to launch the app and "The gradle command failed" HOT 5
- Skip license key expired in free mode HOT 1
- Transpilation problem with lazy variables inside a function HOT 1
- > Inconsistent JVM-target compatibility detected for tasks 'compileDebugJavaWithJavac' (21) and 'compileDebugKotlin' (17). HOT 4
- licence key not found error HOT 2
- Error Setting Up for the frist time HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from skip.