[Feature Request] Const Parameters

オープン
#119 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
lua
領域
compilers

調査の方向性

まず、コンパイラが関数パラメータと test/main.yue で示されている const 変数をどのように処理するかを追跡します。--target=5.1 と --target=5.4 でのコンパイルを比較し、const パラメータが受け入れられ、それへの代入が既存の const 変数の動作と一致して拒否されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Since yuescript does support constvariables (for lua 5.4), I've been playing around with it for a little bit. However, one thing I noticed is that a const parameter cannot be created. I'm not sure if this a thing in lua 5.4 (I've done some Google searching, can't find it), but it would be ideal to allow const in parameters. For example:

test = (const a, b) ->
    a = 3
    return a + b

a = 1
const b = 2

print test a, b

I build this:

 ❯ yue.exe --target=5.1 test/main.yue
Built test/main.yue

It results in:

local test = (const(a, b))(function()
    local a = 3
    return a + b
end)
local a = 1
local b = 2
return print(test(a, b))

Now, even if I built it for lua 5.4, it results in the same compilation, which obviously const isn't supposed to be a valid function here, since I never defined it. I want that to mark the parameter as const so I cannot modify a, or whatever the parameter might be, in the function. I think it should be doable, honestly, because even compiling with const variables for lua 5.1 works perfectly fine, but if you were to modify the variable, yue refuses to build the source file as it should.

Even if const parameters don't exist in lua 5.4, it would be easy to add a check that the variable is marked as such in the parameter and refuse to build the file if you try to modify it, much like with a variable.

主要言語
Lua
スター
620
フォーク
45
平均マージ
9時間 5分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

IppClub/YueScript のほかの issue

IppClub/YueScript の issue をすべて見る

似ている issue

Lua の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。