diff --git a/src/parser.bux b/src/parser.bux index dc5da3f..236ce18 100644 --- a/src/parser.bux +++ b/src/parser.bux @@ -1635,21 +1635,25 @@ func parserParseDecl(p: *Parser) -> *Decl { } discard parserExpect(p, tkLBrace, "expected '{'"); + var methods: *Decl = null as *Decl; + var lastMethod: *Decl = null as *Decl; while !parserCheck(p, tkRBrace) && parserPeek(p, 0) != tkEndOfFile { if parserCheck(p, tkNewLine) { discard parserAdvance(p); continue; } if parserCheck(p, tkFunc) { let m: *Decl = parserParseFuncDecl(p, false, false, false); - // Store method in linked list - if d.methodCount == 0 { - d.childDecl1 = m; - } else if d.methodCount == 1 { - d.childDecl1.childDecl2 = m; + if methods == null as *Decl { + methods = m; + lastMethod = m; + } else { + lastMethod.childDecl2 = m; + lastMethod = m; } d.methodCount = d.methodCount + 1; } else { break; } } + d.childDecl1 = methods; discard parserExpect(p, tkRBrace, "expected '}'"); return d; } diff --git a/src/sema.bux b/src/sema.bux index 84960b7..1b4bf30 100644 --- a/src/sema.bux +++ b/src/sema.bux @@ -565,6 +565,16 @@ func Sema_CheckExpr(sema: *Sema, expr: *Expr) -> int { ai = ai + 1; } } + // Trait bounds checking for explicit generic calls: Max(...) + // Must happen before indirect/direct call returns + if expr.child1.kind == ekIdent { + let sym: Symbol = Scope_Lookup(sema.scope, expr.child1.strValue); + if sym.kind == skFunc && sym.decl != null as *Decl { + if expr.child1.genericTypeArgCount > 0 { + Sema_CheckTraitBounds(sema, sym.decl, expr.child1.genericTypeArg0, expr.child1.genericTypeArg1, expr.child1.genericTypeArgCount, expr.line, expr.column); + } + } + } // Indirect call through function-typed value if calleeType == tyFunc { if expr.child1.refType != null as *TypeExpr && expr.child1.refType.kind == tekFunc { @@ -577,17 +587,11 @@ func Sema_CheckExpr(sema: *Sema, expr: *Expr) -> int { // Direct call to named function if expr.child1.kind == ekIdent { let sym: Symbol = Scope_Lookup(sema.scope, expr.child1.strValue); - if sym.kind == skFunc { - if sym.decl != null as *Decl { - // Trait bounds checking for explicit generic calls: Max(...) - if expr.child1.genericTypeArgCount > 0 { - Sema_CheckTraitBounds(sema, sym.decl, expr.child1.genericTypeArg0, expr.child1.genericTypeArg1, expr.child1.genericTypeArgCount, expr.line, expr.column); - } + if sym.kind == skFunc && sym.decl != null as *Decl { if sym.decl.retType != null as *TypeExpr { return Sema_ResolveType(sema, sym.decl.retType); } } - } } return tyUnknown; }