From ad03579035c2418958d4945e46e05fca54c44a99 Mon Sep 17 00:00:00 2001 From: misterfish Date: Sat, 4 Jun 2016 18:12:41 +0200 Subject: [PATCH] Throw compile-time error if a label is used with a curried function (resolves #751) --- lib/ast.js | 3 +++ src/ast.ls | 1 + test/compilation.ls | 1 + 3 files changed, 5 insertions(+) diff --git a/lib/ast.js b/lib/ast.js index e2d7240a3..77fde28a5 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -4219,6 +4219,9 @@ exports.Label = Label = (function(superclass){ var fun; this.label = label || '_'; this.it = it; + if (this.it.curried) { + this.carp("can't use label with a curried function (attempted label '" + this.label + "')"); + } if (fun = (it instanceof Fun || it instanceof Class) && it || it.calling && it.it.head) { fun.name || (fun.name = this.label, fun.labeled = true); return it; diff --git a/src/ast.ls b/src/ast.ls index fe66ffffe..86d873622 100644 --- a/src/ast.ls +++ b/src/ast.ls @@ -2674,6 +2674,7 @@ class exports.If extends Node # A labeled block or statement. class exports.Label extends Node (@label or \_, @it) -> + @carp "can't use label with a curried function (attempted label '#{@label}')" if @it.curried if fun = it instanceof [Fun, Class] and it or it.calling and it.it.head fun.name or fun <<< {name: @label, +labeled} diff --git a/test/compilation.ls b/test/compilation.ls index 5a12ddd65..01c395ad4 100644 --- a/test/compilation.ls +++ b/test/compilation.ls @@ -35,6 +35,7 @@ compileThrows 'unmatched `]`' 3 '[{\n\n]}' compileThrows 'missing `)CALL`' 1 'f(' +compileThrows "can't use label with a curried function (attempted label 'abc')" 1 ':abc (a, b) --> a + b' throws ''' empty range on line 1