         pattern: []
     else
       atom.label = 'name'
-      id = (ctx.definitionId()) ? (ctx.declarationId symbol) ? ctx.freshId()
+      id = (ctx.definitionId()) ? (ctx.currentDeclarationId symbol) ? ctx.freshId()
       type = toConstrained ctx.freshTypeVariable star
       # ctx.bindTypeVariables [type.type.name]
       ctx.addToDefinedNames {name: symbol, id: id, type: type}

      # log "adding types", (map _symbol, params), paramTypes
      ctx.declareTyped paramNames, paramTypes
      for param in params
        param.id = ctx.declarationId _symbol param

      # Declare wheres first so they properly shadow parent scope
      preDeclarePatterns ctx, _fst unzip pairs wheres

      throw new Error "already defining, forgot to leaveDefinition?"
    @_scope().definition =
      name: pattern?.symbol
      id: pattern?.symbol and (@currentDeclarationId pattern.symbol) or @freshId()
      pattern: pattern
      inside: 0
      late: no
