POLYTONE — the AI-native programming language

Error Lab

Every diagnostic below is the real output of ptc, not a mock-up. Pick a mistake, read how the compiler teaches the canonical form, then flip to the fix.

A bound an importer can name

Since 0.42 a pub function may be bounded by any trait an importer can spell — a built-in, the module's own pub trait, an imported one. A private trait is the one thing nobody outside can name, so no type of theirs could ever satisfy the bound; the error names both ways out.

broken.pt
trait Scored:
    /// The score.
    fn score(self) -> Int

/// The best of the values.
pub fn best[T: Scored](xs: List[T]) -> Int:
    mut top = 0
    for x in xs:
        if x.score() > top:
            top = x.score()
    return top
The compiler answers
error: 'best' is bounded by 'Scored', a trait this module keeps private — an importer could never name it, so no type of theirs could satisfy the bound. Declare 'pub trait Scored:' (an importer then spells it module-qualified, like every imported name), or drop 'pub' from the function (line 5, column 1)