Teyru

Teyru 診斷碼一覽

每個診斷的穩定代碼格式 TY-<階段>-<四位數字>,以及各階段的代表訊息。

每個診斷都有穩定代碼,格式為 TY-<階段>-<四位數字>。階段前綴:

前綴階段代表
TY-SYN詞法與語法分析分號、括號、換行、字面值
TY-TYP語意分析(名稱、型別、成員)找不到符號、型別不符、多載
TY-PROP原生 property 規則accessor 衝突、儲存需求
TY-INT編譯器內部/前導程式庫前導程式庫損壞、未支援的節點
TY-IO檔案存取讀不到來源檔

輸出格式為 檔案:行:欄: error[碼]: 訊息,例如:

hello.teyru:4:11: error[TY-TYP-0051]: incompatible types: String cannot be converted to int

TY-SYN-0001000200040011 由詞法分析器產生(TY-SYN-0003 例外:它是剖析器 在敘述結尾與 throw 換行時發出的),TY-SYN-0100 之後也由剖析器產生。


TY-SYN:詞法與語法

代碼訊息說明與修法
TY-SYN-0001';' is not Teyru syntax; end statements with a newlineTeyru 沒有分號。刪掉分號,讓敘述以換行結束;for 標頭改用冒號分隔。
TY-SYN-0002unexpected character %q出現不屬於任何 token 的字元(多半是全形標點或貼上的控制字元)。
TY-SYN-0003expected end of line, found %sthrow expression must start on the same line敘述後面還有殘餘 token;或 throw 的運算式被換行切斷。把運算式寫在同一行,或用 ( 開頭讓它跨行。需要值的 yield 沒有這個訊息:換行後它被當成識別字,會得到 cannot find symbol yield
TY-SYN-0004unterminated block comment/* 沒有對應的 */
TY-SYN-0005invalid unicode escape\uXXXX 不是四位十六進位。
TY-SYN-0006unterminated string literalunterminated text block字串在換行前沒有收尾,或 text block 少了結尾的 """
TY-SYN-0007text block must start with a line break after """""" 之後必須立刻換行。
TY-SYN-0008unterminated character literalcharacter literal does not fit in a char字元常值沒有收尾,或超過 U+FFFF。
TY-SYN-0009malformed integer literalmalformed floating-point literal數字格式錯誤(例如 0x 後面沒有數字、1e 沒有指數)。
TY-SYN-0010integer literal out of range整數字面值超出可表示的位元數:十進位 int 上限 2^31-1、long 上限 2^63-1,非十進位 int 上限 0xFFFFFFFFlong 上限 0xFFFFFFFFFFFFFFFF(界線值會繞成負數)。需要更大的值請加 L 後綴。
TY-SYN-0011invalid escape sequence \%c字串或字元常值裡有 Teyru 不認識的跳脫序列(例如 \q)。合法的有 \n \t \r \b \f \s \0 \\ \' \"、八進位 \nnn\uXXXX
TY-SYN-0100expected '%s', found %s少了預期的 token()]{}: 等)。
TY-SYN-0101expected identifier, found %s需要識別字的位置放了別的東西;常見於把關鍵字當名稱使用。
TY-SYN-0102unexpected %s at top level檔案最上層只允許 package/import/型別宣告,或直接寫成員(隱式類別形式)。
TY-SYN-0103unexpected %s in class body類別成員宣告不完整。
TY-SYN-0104expected ',' ':' or '}' after enum constantsenum 常數區與成員區之間要用一個 : 分隔。
TY-SYN-0105expected 'get' or 'set' accessor, found %saccessor 區塊裡只能有 getset
TY-SYN-0106unexpected %s區塊內出現無法剖析的敘述。
TY-SYN-0107try resources must be separated by line breakstry-with-resources 的每個資源用換行分隔,不能用分號。
TY-SYN-0108try requires catch or finallytry 至少要有一個 catchfinally
TY-SYN-0109expected 'case' or 'default', found %sswitch 區塊裡只能有 casedefault
TY-SYN-0110cannot mix '->' and ':' case labels同一個 switch 只能用一種標籤形式。
TY-SYN-0111expected expression, found %s需要運算式的位置放了別的 token。
TY-SYN-0112array dimension expression after empty dimensionnew int[3][] 之後不能再寫 [5]
TY-SYN-0113array creation with both dimensions and initializernew int[3]{1,2,3} 不合法;要嘛給大小,要嘛給初始值。

TY-TYP:型別與符號

宣告與成員(0001–0025)

代碼訊息說明與修法
TY-TYP-0001duplicate type %sduplicate nested type %s同名型別重複宣告。
TY-TYP-0002type variable %s cannot have type arguments型別變數不能再帶型別引數。
TY-TYP-0003cannot find type %s型別名稱找不到;檢查拼字、import 或前導程式庫。
TY-TYP-0004type %s expects %d type arguments, found %d泛型引數數量不符。
TY-TYP-0005primitive type %s cannot be a type argument泛型不能用原生型別,請用包裝類別。
TY-TYP-0006class cannot extend interface %s類別要用 implements 介面。
TY-TYP-0007cannot extend final class %sfinal 的類別不能被繼承。final@Value@UtilityClass 標上去時,這一條在標註展開之後才報(「擋下繼承」的檢查原本跑在展開之前,所以那兩個標註沒有作用)。
TY-TYP-0008cyclic inheritance involving %s繼承關係成環。
TY-TYP-0009%s is not an interfaceimplements 後面只能是介面。
TY-TYP-0010duplicate field %s in %s同一個類別重複宣告欄位。
TY-TYP-0011duplicate method %s in %sduplicate constructor %s參數抹除後簽章相同的方法或建構子重複。
TY-TYP-0012varargs parameter must be last... 只能放在最後一個參數。
TY-TYP-0013interface method with a body must be default, static or private介面方法有 body 時要標 defaultstaticprivate
TY-TYP-0014method %s needs a body非抽象方法要有 body。
TY-TYP-0015abstract or native method %s cannot have a bodyabstractnative 方法不能有 body。
TY-TYP-0016abstract method %s in non-abstract class %s有抽象方法的類別必須標 abstract
TY-TYP-0017(已移除)native 方法現在可以宣告在任一類別,並以 --native 提供的 C 實作。
TY-TYP-0018'%s' is only allowed for local variablesvarval 不能用在欄位、參數或回傳型別。
TY-TYP-0019%s must implement %s from %s具體類別沒有實作介面或父類別的抽象方法。
TY-TYP-0020missing return statement有回傳值的方法在某些路徑沒有 return
TY-TYP-0021duplicate local variable %s同一個作用域重複宣告區域變數。
TY-TYP-0022break outside of loop or switchbreak 只能出現在迴圈或 switch 內(有標籤者除外)。
TY-TYP-0023continue outside of loopcontinue 只能出現在迴圈內。
TY-TYP-0024thrown value must be a Throwablethrow 的物件必須繼承 Throwable
TY-TYP-0025cannot synchronize on voidsynchronized 的鎖不能是 void 運算式。

陳述式(0026–0044)

代碼訊息說明與修法
TY-TYP-0026local variables cannot be declared final; use 'val'區域變數的不可重綁請用 val
TY-TYP-0027'%s' requires an initializervarval 一定要有初始值。
TY-TYP-0028'%s' cannot infer a type from nullnull 無法推斷型別,請寫出明確型別。
TY-TYP-0029'%s' cannot infer a functional interface typelambda 需要目標型別,請明確宣告介面型別。
TY-TYP-0030for-each requires an array or Iterable增強 for 只能用在陣列或 Iterable
TY-TYP-0031incompatible types: %s is not assignable to %s迴圈變數型別與元素型別不符。
TY-TYP-0032return value required for %s有回傳值的方法不能空手 return
TY-TYP-0033cannot return a value from a void methodvoid 方法不能回傳值。
TY-TYP-0034catch type must be a Throwablecatch 的型別必須是 Throwable 家族。
TY-TYP-0035switch selector must be a char, byte, short, int, Character, Byte, Short, Integer, String or enum type, found %sswitch 的選擇子型別不合法。
TY-TYP-0036duplicate default label同一個 switch 只能有一個 default
TY-TYP-0037incompatible pattern type %s for switch on %scase 型別 名 與選擇子型別無關。
TY-TYP-0038case label must be a constant expressioncase 標籤必須是編譯期常數。
TY-TYP-0039duplicate case label同一個 switch 內標籤重複。
TY-TYP-0040array required, found %s對非陣列使用 []
TY-TYP-0041inconvertible types: %s cannot be cast to %s這個 cast 永遠不可能成立。
TY-TYP-0042incompatible pattern type %s for %sinstanceof pattern 的型別與左邊無關。
TY-TYP-0043not an enclosing class: %sOuter.this 的外層類別不存在。
TY-TYP-0044no superclass沒有父類別卻使用 super

名稱與存取(0045–0048)

代碼訊息說明與修法
TY-TYP-0045cannot access instance field %s from a static context靜態方法內不能直接讀實例欄位。
TY-TYP-0046%s has private access in %s私有成員只能在自己的類別內存取。property 看的是 accessor 的修飾符(底層儲存一律 private,所以儲存欄位的修飾符不能拿來判斷);x.p = v 看 setter,p.xp.x += 1 看 getter。同一個 nest(同一個最外層類別)內互通。
TY-TYP-0048cannot find symbol %s名稱找不到:檢查拼字、作用域、import,或是否忘了宣告。

型別轉換與運算子(0049–0067)

代碼訊息說明與修法
TY-TYP-0049null is not assignable to %snull 不能給原生型別。
TY-TYP-0050possible lossy conversion from %s to %s需要窄化轉換,請加 cast。
TY-TYP-0051incompatible types: %s cannot be converted to %s最常見的型別錯誤:指派、傳參、回傳的型別不相容。
TY-TYP-0052operator '!' cannot be applied to %s! 只能用在 boolean
TY-TYP-0053operator '~' requires an integral operand~ 只能用在整數。
TY-TYP-0054operator '%s' requires a numeric operand一元 +- 只能用在數值。
TY-TYP-0055operator '%s' requires a numeric operand++-- 只能用在數值。
TY-TYP-0056cannot apply '%s' to a non-assignable expression++-- 的目標必須可以被指派。
TY-TYP-0057cannot assign a value to final variable %svalfinal 變數不能再次指派。
TY-TYP-0058cannot assign a value to final field %s不能指派其他類別的 final 欄位。
TY-TYP-0059incompatible operand types %s and %s==!= 兩邊型別無法比較。
TY-TYP-0060incomparable types: %s and %s兩個參考型別之間不可能相等。
TY-TYP-0061operator '%s' cannot be applied to %s and %s大小比較只能用在數值。
TY-TYP-0062operator '%s' requires integral or boolean operands&|^ 的運算元型別不合法。
TY-TYP-0063operator '%s' requires integral operands位移運算子只能用在整數。
TY-TYP-0064operator '%s' cannot be applied to %s and %s算術運算子的運算元不是數值(常見:物件忘了 unbox)。
TY-TYP-0065left-hand side of an assignment must be a variable指派的左邊不能是任意運算式。
TY-TYP-0066operator '%s' cannot be applied to booleanboolean 不能做加減乘除。
TY-TYP-0067array dimension must be non-negative陣列大小是負的常數。

建構與實例化(0068–0075)

代碼訊息說明與修法
TY-TYP-0068cannot instantiate %s這個型別不能用 new
TY-TYP-0069%s is abstract; cannot be instantiated抽象類別不能直接 new
TY-TYP-0070cannot extend final class %scannot subclass enum %s匿名類別不能繼承 final 類別或 enum。
TY-TYP-0071an enclosing instance of %s is required內部類別需要在有外層實例的地方建立。
TY-TYP-0072no suitable constructor found for %s(%s)沒有相符的建構子;檢查參數數量與型別。
TY-TYP-0073array clone takes no argumentsclone() 不接受參數。
TY-TYP-0074this(...) and super(...) may only be called from a constructorthis(...)super(...) 只能寫在建構子裡(可以是 JEP 513 允許的「super() 之前的敘述」之一,見 docs/language.md §4.2)。
TY-TYP-0075recursive constructor invocation建構子遞迴呼叫自己。

方法解析、lambda 與 pattern(0076–0094)

代碼訊息說明與修法
TY-TYP-0076cannot find method %s(%s)cannot find method %s for this functional interface找不到方法:檢查名稱、參數型別、可見性,或受體型別。
TY-TYP-0077non-static method %s cannot be referenced from a type name用類別名稱只能呼叫靜態方法。
TY-TYP-0078cannot invoke %s on %s對這個型別呼叫方法不合法。
TY-TYP-0079%s has %s access in %s方法可見性不足。
TY-TYP-0080cannot find symbol %s in %son array成員不存在於該型別。
TY-TYP-0081cannot infer the functional interface for this lambdalambda/方法參照沒有目標型別,請明確指定。
TY-TYP-0082lambda target type must be a functional interface目標型別不是介面。
TY-TYP-0083%s is not a functional interface介面有多個抽象方法,不能當 lambda 目標。
TY-TYP-0084lambda has %d parameters but %s requires %dlambda 參數數量不符。
TY-TYP-0085cannot construct %s建構子參照的目標不能建構。
TY-TYP-0086cannot resolve static import %s靜態 import 找不到對應成員。
TY-TYP-0087record pattern requires a record type, found %s解構 pattern 的左邊不是 record 型別(case Point(int x, int y)Point 必須是 record)。
TY-TYP-0088record pattern for %s needs %d components, found %d解構的綁定數量與 record 成員數不符;巢狀解構也要逐一對上。
TY-TYP-0089'case null' requires a reference selectorcase null 只能用在參考型別的 switch 選擇子上,原生型別請改用 default
TY-TYP-0090%s does not name a super interfaceInterface.super.method()Interface 不存在或不是介面。
TY-TYP-0091%s is not a super interface of %s限定的 super 只能指向自己(直接或間接)實作的介面。
TY-TYP-0092a primitive pattern needs a name to bind the value to原生型別 pattern 一定要綁定變數:o instanceof int i,不能只寫 o instanceof int
TY-TYP-0093boolean cannot be converted to %sboolean 只能和 boolean pattern 配對。
TY-TYP-0094primitive pattern %s needs a boxed value, found %s選擇子既不是參考型別也不是原生數值。
TY-IO-0101模組檔本身的錯誤(teyru.mod 無法解析、版本語法不對…)訊息來自 internal/mod,指出檔案與原因。
TY-IO-0102cannot read package %s: %v匯入的套件在模組快取裡找不到,或它的原始檔讀不出來。先跑 teyru mod tidyteyru get
TY-IO-0103teyru.sum 的雜湊不符快取裡的模組內容與 teyru.sum 記的不一樣。要嘛是依賴被改過,要嘛是快取被動過;建置會停下來而不是用下去。
TY-IO-0104%s declares package %s, but %s in the same directory declares %s同一個目錄裡的兩個檔案宣告了不同的套件。
TY-TYP-0095cannot infer the type arguments of %s(%s)泛型方法的型別引數推不出來:沒有帶型別的引數,也沒有目標型別可用(lambda 參數最常見)。寫出型別引數或給一個有型別的引數。
TY-TYP-0096switch expression does not cover all possible input valuesswitch 運算式必須窮盡:intString 選擇子一定要有 default,列舉選擇子要涵蓋每一個常數。switch 陳述式不受此限。
TY-TYP-0097native methods %s and %s both need the C symbol %s兩個多載 native 方法編碼後得到同一個 C 符號(例如類別名 AIint[])。改名或改參數型別。
TY-TYP-0098non-static %s cannot be referenced from a static contextlambda 主體用到撰寫處的 this(含未限定的實例方法呼叫、裸欄位名與 super),但 lambda 寫在 static 方法或 static 初始化區塊裡,沒有實例可捕獲。Java 同樣拒絕。
TY-TYP-0108%s is a prelude class; it has no generated JSON binding對前置類別(String、JsonObject…)要求產生 JSON 綁定。
TY-TYP-0109two fields of %s both map to the JSON name %s兩個欄位經 @SerializedName 後同名。
TY-TYP-0112%s is bound from JSON but has no no-argument constructor; ...Gson 用 Unsafe 繞過建構子配置物件,Teyru 沒有,所以從 JSON 讀取的類別需要一個無參建構子。
TY-TYP-0111%s answers with %s, which has no JSON mapping; ...controller 方法的回傳型別沒有 JSON 映射(陣列、List…)。改回傳 String 或 HttpResponse,或是一個綁定走得完的類別。
TY-TYP-0110%s has no JSON mapping for its type %s欄位型別沒有 JSON 映射。Gson 在執行期才拋,這裡在綁定的那一行就報。
TY-TYP-0114not a statement: %s has no effect沒有副作用的運算式陳述式(JLS 14.8)。這個語言在換行結束運算式,所以 long x = a 換行 + b 是兩個陳述式,第二個是安靜的一元加號——x 少一項而沒有任何訊息。現在會報出來。
TY-TYP-0113resource type %s is not a subtype of AutoCloseabletry-with-resources 的資源型別必須是 AutoCloseable 的子型別。隱含的 close() 是一次介面呼叫,所以「剛好有 close() 方法」的類別會編成物件沒有項目的 itable 呼叫,執行期才爆。
TY-TYP-0115cannot resolve import %s匯入路徑指不到任何東西。名字在 Teyru 裡是照簡單名稱找的,前面寫什麼套件都一樣,所以 import java.utli.List 這種拼錯的套件以前是安靜地被忽略、然後照樣拿到 List。現在匯入必須指向:標準程式庫回答的套件(teyru 本身,以及相容用的 java.utilcom.google.gsonlombok…,見 docs/language.md §11)、本次建置某個檔案宣告的套件、或是一個完整名稱就是這條路徑的型別。
TY-TYP-0100two beans are named %s: %s and %s兩個 bean 取了同一個名字(@Component("x")@Bean("x"))。
TY-TYP-0101%s is declared by the framework and cannot be redefined__TeyruFramework 是容器註冊用的合成類別,名字被保留。
TY-TYP-0102@Bean method %s ...@Bean 方法必須不是 static、且回傳型別是一個類別(基本型別會裝箱)。
TY-TYP-0103no bean of type %s to inject into %s某個 @Autowired 的型別沒有任何 bean。Spring 在啟動時才發現,這裡在編譯期。
TY-TYP-0104%d beans of type %s: name one with @Qualifier同型別有多個 bean,沒有 @Primary 也沒有 @Qualifier
TY-TYP-0105two constructors of %s are annotated @Autowired / %s has %d constructors and none is annotated @Autowired建構子注入的選擇規則:單一建構子、或標了 @Autowired 的那一個。
TY-TYP-0106@PostConstruct method %s must take no arguments and return void生命週期回呼的簽章。
TY-TYP-0107circular dependency: %sbean 之間的相依形成環。Spring 在啟動時拋例外,這裡在編譯期就拒絕。
TY-TYP-0099reference to %s is ambiguous: it is declared in both %s and %s兩個 import p.* 都提供同一個簡單名稱(JLS 6.5.5.1)。寫出完整名稱或用單一類型匯入(import a.Widget)消歧義。

TY-PROP:原生 property

代碼訊息說明與修法
TY-PROP-0001a property declaration must declare exactly one name一個 property 只能宣告一個名稱。
TY-PROP-0002duplicate get accessorduplicate set accessorgetset 各只能出現一次。
TY-PROP-0003computed property %s cannot use storage modifiers沒有儲存的 property 不能用 finalvolatiletransient
TY-PROP-0004final property %s cannot declare a setterfinal property 不能有 setter。
TY-PROP-0005property %s has no getter只有 setter 的 property 不能被讀取;在 accessor 內請用 field
TY-PROP-0007property %s has no setter只有 getter 的 property 不能被指派。
TY-PROP-0008property %s needs a getter for compound assignmentp.x += 1 需要 getter 與 setter。

TY-INT 與 TY-IO

代碼訊息說明
TY-INT-0001prelude is missing class %s前導程式庫損壞或類別被覆蓋,屬於編譯器內部錯誤。
TY-INT-0002unsupported expression %T語意分析遇到未處理的節點,屬於編譯器內部錯誤(請回報)。
TY-INT-0004@Singular goes on a builder field, not on the class寫在類別上沒有意義。
TY-INT-0005@Singular needs a List or Map field, found %s@Singular 只能用在集合欄位。
TY-INT-0006@CustomLog needs %s in a %s file in the source file's directory or above it@CustomLog cannot pass TYPE: …@CustomLog: cannot resolve the factory class %q named by %s@CustomLog 要靠 lombok.configlombok.log.custom.declaration 才知道怎麼建 logger(讀法見 docs/lombok.md):沒有這個鍵、樣式用了 TYPE、或樣式指的類別找不到,都在這裡報。也可以改用 @Log 或自己宣告欄位。
TY-IO-0001cannot read %s: %v來源檔讀不到,檢查路徑與權限。

執行期錯誤

執行期的失敗不是診斷碼,而是 Throwable 家族:

例外觸發時機
NullPointerExceptionnull 拆箱,或讀寫欄位、呼叫方法(String 的方法、clone()、介面方法與虛擬呼叫都是)、讀寫陣列元素或取 length
ArrayIndexOutOfBoundsException陣列索引超出 [0, length)(讀與寫都是;null 陣列先丟 NullPointerException
IndexOutOfBoundsExceptionArrayList.getsetremove 的索引超出 [0, size)
NoSuchElementException已經沒有元素卻再呼叫 Iterator.next()
ArithmeticException整數除以零或取餘數為零
ClassCastExceptioncastinstanceof 失敗的強制轉型
NegativeArraySizeException陣列長度為負
AssertionErrorassert 失敗
IllegalArgumentExceptionenum.valueOf 找不到常數等

沒有被 catch 的例外會印出 Exception in thread "main" … 並以狀態 1 結束。 若執行到沒有實作的抽象方法,會印出 teyru: no implementation for … 並以狀態 70 結束。

本頁內容