Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Assignment as last expression in function doesn't return #32

Open
ckknight opened this Issue · 1 comment

2 participants

Cameron Knight leaf
Cameron Knight

Use case:

cache = {}
func = (key) ->
  value = cache[key]
  if value ~= nil
    value
  else
    cache[key] = value + 1

Expected compilation:

local cache = { }
local func
func = function(key)
  local value = cache[key]
  if value ~= nil then
    return value
  else
    local _result = value + 1
    cache[key] = _result
    return _result
  end
end

Current compilation:

local cache = { }
local func
func = function(key)
  local value = cache[key]
  if value ~= nil then
    return value
  else
    cache[key] = value + 1
  end
end
leaf
Owner

This has to do with #31, assignment isn't an expression so it doesn't turn into a return statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.