Skip Lite: views re-exported through a non-Skip umbrella target are silently dropped in @ViewBuilder

Aperta
#753 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
22/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
kotlin, swift

Direzione di ricerca

Start with the repro repo and run swift package --allow-writing-to-package-directory skip-transpile on UsesUmbrella versus UsesDirect to compare the generated DemoView.kt. The relevant code is in SkipTranspile.swift (the umbrella-skipping logic around lines 204-221), CodebaseInfo.swift (expandWithExportedImports and rankScore), and KotlinSwiftUITransformer.swift (translateViewBuilder and translateFunctionCall). Done means Badge gets .Compose(composectx) and Card's trailing closure is wrapped in ComposeBuilder when imported through the umbrella, with the output matching the direct import.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Some of our packages use a thin umbrella target (no Skip/skip.yml) whose only content is @_exported import Core, so that consumers can import CoreUmbrella. A Skip module that imports the umbrella gets broken Kotlin for any Core view used inside a @ViewBuilder:

  • Badge() is emitted without .Compose(composectx), so it never renders.
  • Card { Text("a"); Text("b") } becomes a plain lambda, so only the last child survives and Card itself is not composed.

Swift, the transpile and Kotlin all compile without errors. The only sign is a generic "Skip is unable to match this API call" warning, and it only appears when the file is re-transpiled.

Skip 1.9.19, skip-ui 1.64.0, skip-foundation 1.4.8. The code involved is unchanged on main.

Repro

https://github.com/daniboybye/skip-umbrella-viewbuilder-repro

// Inner (Skip module):     public struct Badge: View, public struct Card<Content: View>: View { init(@ViewBuilder content:) }
// InnerUmbrella (no skip.yml):
@_exported import Inner

// UsesUmbrella (Skip module); UsesDirect is identical but uses `import Inner`
import InnerUmbrella
import SwiftUI

public struct DemoView: View {
    public var body: some View {
        VStack {
            Badge()
            Card { Text("a"); Text("b") }
        }
    }
}
swift package --allow-writing-to-package-directory skip-transpile

Generated DemoView.kt, UsesDirect → UsesUmbrella:

-                    Badge().Compose(composectx)
+                    Badge()
                     Card { ->
-                        ComposeBuilder { composectx: ComposeContext ->
-                            Text(LocalizedStringKey(stringLiteral = "a")).Compose(composectx)
-                            Text(LocalizedStringKey(stringLiteral = "b")).Compose(composectx)
-                            ComposeResult.ok
-                        }
-                    }.Compose(composectx)
+                        Text(LocalizedStringKey(stringLiteral = "a"))
+                        Text(LocalizedStringKey(stringLiteral = "b"))
+                    }

Cause

  1. The plugin recurses through InnerUmbrella, skips it because it has no skip.yml, and still links Inner (SkipTranspile.swift#L204-L221). So Inner's symbols are loaded, but skipstone never learns that InnerUmbrella re-exports Inner.
  2. expandWithExportedImports only follows re-exports declared by Skip modules (skiptools/skipstone#256). Inner is therefore not visible to the file, and rankScore returns 0 for Badge and Card.
  3. With no API match, translateViewBuilder adds no .Compose, and translateFunctionCall doesn't treat the trailing closure as a @ViewBuilder.

It goes unnoticed when Inner's skip.yml sets package: to the name derived from the umbrella (inner.umbrella), because import inner.umbrella.* then resolves. That is our setup.

Workaround

import InnerUmbrella
#if SKIP
import Inner
#endif

Calling the view through a local function (func badge() -> some View { Badge() }) also works for plain views, but not for @ViewBuilder containers.

Proposed fix

  • skip plugin: for a dependency target without skip.yml, pass --umbrella-module InnerUmbrella:<dir> and add its sources to the plugin inputs.
  • skipstone: parse those files, collect their @_exported imports of linked modules, and register a symbol-less ModuleExport for the umbrella with those exportedModuleNames. The #256 code handles the rest. Also skip the umbrella's own Kotlin import unless it matches a real package.

A local skipstone test confirms that adding such a stand-in ModuleExport restores both .Compose calls with no other change.

Separately, it would help if an unmatched bare initializer inside a @ViewBuilder produced a clearer diagnostic, since its result is silently discarded.

If this direction works for you, I'm happy to send PRs for skip and skipstone.

Lingua principale
Swift
Stelle
3.3k
Fork
115
Merge medio
1g 15h
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di skiptools/skip

Tutte le issue di skiptools/skip

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.