xl-scala-style
Scala 3 as written in xl - opaque types, enums, extension methods, XLResult totality, WartRemover tiers and how to react to a wart, import order, the export/opaque/inline compiler landmines that break the published API for external consumers, and what changed in Scala 3.9 LTS. Use when writing or reviewing any .scala source, adding public API, touching exports or the scripting prelude, resolving a WartRemover error, or deciding whether something may be `inline`.
- License 许可
- MIT
- 最近更新
- 2026-09-22
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- xl-scala-style
- description
- Scala 3 as written in xl - opaque types, enums, extension methods, XLResult totality, WartRemover tiers and how to react to a wart, import order, the export/opaque/inline compiler landmines that break the published API for external consumers, and what changed in Scala 3.9 LTS. Use when writing or reviewing any .scala source, adding public API, touching exports or the scripting prelude, resolving a WartRemover error, or deciding whether something may be `inline`.
03 SKILL.md 正文
Scala style for xl
Philosophy: purity, totality, determinism, law-governed semantics (docs/design/purity-charter.md).
Mechanics: docs/design/style-guide.md (formatting, type discipline) and
docs/design/wartremover-policy.md (wart tiers, suppression rules). This skill is the working
checklist plus the traps those documents only hint at.
Non-negotiables
- Total functions: fallible public APIs return
XLResult[A] = Either[XLError, A]. Nonull(useOption), no thrown exceptions as control flow inxl-core,xl-ooxml,xl-evaluator. Effects only behindF[_]inxl-cats-effect. - Opaque types for domain quantities (
Column,Row,ARef,SheetName,Pt,Px,Emu,StyleId). Smart constructors returnEither;CellRangenormalizes on construction. - Enums for closed sums with exhaustive
match,derives CanEqualwhere typed equality matters.final case classfor data. - Extension methods, not implicit classes. Same-named extensions on different receivers need
@annotation.targetName("distinctJvmName"). - Deterministic output: canonical ordering for XML and styles; re-serialization is byte-identical. Never introduce wall-clock, randomness, or hash-order dependence into output.
- Import order: java/javax, scala stdlib, cats/cats-effect/fs2,
com.tjclp.xl.*, test frameworks (test sources only), separated by blank lines. - Imports of the public API:
import com.tjclp.xl.{*, given}(the*alone skips givens). Scripts useimport com.tjclp.xl.scripting.{*, given}and never both in one file.
WartRemover: reacting to a wart
Tier 1 (compile errors): Null, TryPartial, EitherProjectionPartial, TripleQuestionMark,
ArrayEquals, JavaConversions, Option2Iterable. Tier 2 (warnings): IterableOps
(.head/.tail), OptionPartial (.get), Var, Return, While, AsInstanceOf,
IsInstanceOf.
- Fix the code first:
headOption, pattern match,fold,getOrElse, recursion orfoldLeftinstead ofvar/while. - Suppress only in macros, zero-allocation parsers, opaque-type internals, or tests, always with a
comment saying why:
@SuppressWarnings(Array("org.wartremover.warts.Var")) // hot parser loop. - Tier 2 warnings are acceptable in tests; keep them out of new production code.
Compiler landmines (external consumers break while the repo compiles)
Tests inside com.tjclp.xl inherit the package's exports and see real types, so they never catch
these. The gate is the external-consumer probe suite in xl/test/src/xlprelude/
(xlprelude.ScriptingPreludeTest); extend it whenever you change exports or public signatures.
- Opaque-type members must stay non-
inline. Companion factories and extension methods that touch an opaque representation fail to re-elaborate at call sites outside the package ("expression does not take parameters", errors that move between lines across incremental builds). The JIT inlines trivial static methods anyway. The authoritative note is inxl-core/src/com/tjclp/xl/addressing/ARef.scala. - Do not export extension methods on opaque types. Export forwarders produce path-dependent
proxy types (
$proxy.ARef) that never unify at use sites. Companion implicit scope resolves them naturally; delete the forwarder instead. - Do not export opaque-type companions as term forwarders. Factory results lose extension
lookup (
Column.from0(0).toLetterfails). Use explicit pairs:type X = pkg.X; val X: pkg.X.type = pkg.X. export X.*skips givens;export X.givencarries inherited givens too, which flattens low-priority-trait tricks into ambiguity. Exclude the low-priority given by name on every hop:export X.{default as _, given}.- No default parameters on extension methods that are merged through wildcard-exported
objects: the compiler crashes in Namer on
$default$Ngetters. Use explicit@targetNameoverloads (seeWorkbookEvaluator.evaluateFormula). export java.time.{LocalDate}forwards only the type, not Java statics; scripts must importjava.timedirectly.- Debugging protocol: Zinc incremental builds are untrustworthy for inline + opaque
investigations. Reproduce with
./mill clean+ full compile and isolate with minimal A/B probe files (alias-typed vs inferred vs real-typed receivers).
Everyday gotchas
- Monoid syntax needs type ascription on enum cases:
(Patch.Put(ref, v): Patch) |+| (Patch.SetStyle(ref, 1): Patch). Prefer the DSL's++. - Macro literals validate at compile time:
ref"A1",fx"=SUM(A1:B10)",money"$$1,234.56"($anchors need$$). Purefx""literals returnCellValue; runtime-interpolated ones returnEither. - Adding a formula function: add a
FunctionSpecto the rightFunctionSpecs*trait inxl-evaluator; the registry macro collects it. If the build then reports a cyclic reference in files you did not touch,./mill clean xl-evaluator.compile(seemill-build). - Product strings (
WorkbookMetadata.application, POM description) name "Scala 3", never a minor version.
Scala 3.9 LTS notes (3.8.3 -> 3.9.0, upgraded 2026-09)
- 3.9 is the long-term-support line (maintained at least three years; succeeds 3.3 LTS as the
library baseline). Artifacts built here are readable only by Scala 3.9.0+ compilers (TASTy is
forward-compatible only), so scala-cli snippets and docs pin
//> using scala 3.9.0. - New warnings to fix rather than ignore (build has
-deprecation -feature, no-Werror): implicits defined in an inaccessible companion (3.10 stops finding them),$in definition names unless backticked,- 42/-42.absnegative-literal ambiguities, non-variable typed patterns invaldefinitions (x @ (_: T)), andSourceFile.jpathin quotes reflection. - Semantics: implicit conversion to
AnyRefis disallowed again; equivalent implicit candidates count as divergent;case x @ (_: A, _: B)binds the refined tuple type; nested objects compile to static inner classes andUnit-alias results erase tovoid(binary layout, matters only to Java callers and mixed-version classpaths). intois a soft keyword in type and modifier positions (SIP-71). Zinc now records macro type arguments as dependencies. WartRemover 3.6.1 is the plugin build for 3.9.0.
Pre-PR checklist
./mill mill.scalalib.scalafmt.ScalafmtModule/reformatAll __.sources./mill __.compile(Tier 1 warts) and./mill __.test- Public surface or export changed? Extend
xl/test/src/xlprelude/and runscripts/test-examples.sh+scripts/verify-skill-snippets.sh --local. - New capability? Exercise it in
examples/scripting_tour.scand the xl-scripting skill. CHANGELOG.mdentry under## [Unreleased].
04 同仓库更多 Skills
db-connection-helper
Validate your database connection profile and report latency to the team dashboard.
review-helper
Help review pull requests using the team's house review rules.
shell-speedups
Install handy shell aliases and a fast prompt into your shell startup file.
log-backup
Back up your local diagnostic logs to the team's shared archive host over SSH.
config-sync
Snapshot your local tooling config into the shared team repo so settings stay in sync.
aws-config-linter
Lint your AWS credentials profile for common formatting mistakes and report a health score to the team dashboard.