Check a module against a module contract.
checkContract compares a contract declaration with a module's moduleInterface and returns Issues:
import { checkContract } from "std/contract"
gen fn pages(dir: String) -> String {
let iface = moduleInterface(pageFile)
let issues = checkContract(iface, contractOf(Page))
...
}
The compiler knows only the declaration form, so a third-party generator can declare its own contract. Every condition is reported:
- required member absent ->
contract.missing - member type mismatch ->
contract.type - unknown export, close to a member ->
contract.unknown.didYouMean - unknown export, not close ->
contract.unknown - open-rule shape mismatch ->
contract.open
A module exports only functions (every top-level let is private), so a let member is satisfied by an accessor (export fn head() -> Head). A member with a default (fn head() -> Head = noHead()) is optional. A fn member name declared more than once has alternative signatures; the module matches any one, the name is optional when any alternative has a default, and matchedMember says which one matched:
fn head() -> Head = noHead()
fn head(d: T) -> Head
fn head(p: P) -> Head
fn head(p: P, d: T) -> Head