~/bend-docscommunity

src/rules/correctness/foreign.bend checks

raw source on the hub · import 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/rules/correctness/foreign.bend as Foreign

rule foreign: a foreign def (its body only import "./x.c" / import "./x.js" lines) with a body for one lane and not the other. Each lane finds out only when it first runs: a native build (bend -o bin) fails with "no .c import", an interpreted or JS run with "a foreign def without a .js import". Give every foreign def both bodies, x.c and x.js. A file headed # lanes: native never runs on the JS lane, so it needs no .js. Headed means the exact line # lanes: native is one of the file's leading comment lines, those before its first line that does not start with #; the line anywhere later does not count.

7 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../../syntax/bind.bend as Bind
import ../../lazy/lazy.bend as Lazy

Types

type Lanes source · line 19 · raw

Data

which lanes a foreign def's bodies cover

Definitions

def target source · line 23 · raw

@kids:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> String

the imported path of an import statement's tokens ("./x.c", quoted)

def lanes.go source · line 33 · raw

@body:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> @cc:Bool -> @js:Bool -> Maybe<&2, Lanes>

the lanes of a body that is only imports; None when it is anything else

def lanes source · line 44 · raw

@body:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> Maybe<&2, Lanes>

the lanes of a def's body: None unless it is a foreign def

def lack source · line 53 · raw

@mm:Maybe<&2, Lanes> -> @+native:Bool -> @+name:String -> String

what the lanes lack, as a message ("" for nothing)

def at source · line 64 · raw

@+msg:String -> @+line:U32 -> @+col:U32 -> @+path:String -> @+more:List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding> -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>

a message as a finding, when there is one

def name.of source · line 68 · raw

@mm:Maybe<&2, String> -> String

a def's name, ? when it has none

def check.go source · line 75 · raw

@root:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/syntax/tree.Node -> @+native:Bool -> @+path:String -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>

def native_only.go source · line 85 · raw

@ls:List<&2, String> -> Bool

def native_only source · line 95 · raw

@text:String -> Bool

is the file headed # lanes: native: that exact line among the comment lines before its first line that is not a comment?

def check source · line 99 · raw

@ss:0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/src.Src -> List<&2, 0x582b4b0fdf3dafdeecc8c3bfddc5e4db/src/finding.Finding>

the rule