error.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. package checker
  2. import (
  3. "fmt"
  4. "kumachan/loader"
  5. . "kumachan/error"
  6. )
  7. type TypeError struct {
  8. Point ErrorPoint
  9. Concrete ConcreteTypeError
  10. }
  11. type ConcreteTypeError interface { TypeError() }
  12. func (impl E_ModuleOfTypeRefNotFound) TypeError() {}
  13. type E_ModuleOfTypeRefNotFound struct {
  14. Name string
  15. }
  16. func (impl E_TypeNotFound) TypeError() {}
  17. type E_TypeNotFound struct {
  18. Name loader.Symbol
  19. }
  20. func (impl E_WrongParameterQuantity) TypeError() {}
  21. type E_WrongParameterQuantity struct {
  22. TypeName loader.Symbol
  23. Required uint
  24. Given uint
  25. }
  26. func (impl E_DuplicateField) TypeError() {}
  27. type E_DuplicateField struct {
  28. FieldName string
  29. }
  30. func (impl E_InvalidFieldName) TypeError() {}
  31. type E_InvalidFieldName struct {
  32. Name string
  33. }
  34. func (err *TypeError) Desc() ErrorMessage {
  35. var msg = make(ErrorMessage, 0)
  36. switch e := err.Concrete.(type) {
  37. case E_ModuleOfTypeRefNotFound:
  38. msg.WriteText(TS_ERROR, "No such module:")
  39. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  40. case E_TypeNotFound:
  41. msg.WriteText(TS_ERROR, "No such type:")
  42. msg.WriteEndText(TS_INLINE_CODE, e.Name.String())
  43. case E_WrongParameterQuantity:
  44. msg.WriteText(TS_ERROR, "Wrong parameter quantity:")
  45. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Required))
  46. msg.WriteText(TS_ERROR, "required but")
  47. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Given))
  48. msg.WriteText(TS_ERROR, "given")
  49. case E_DuplicateField:
  50. msg.WriteText(TS_ERROR, "Duplicate field:")
  51. msg.WriteEndText(TS_INLINE_CODE, e.FieldName)
  52. case E_InvalidFieldName:
  53. msg.WriteText(TS_ERROR, "Invalid field name:")
  54. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  55. default:
  56. panic("unknown error kind")
  57. }
  58. return msg
  59. }
  60. func (err *TypeError) Message() ErrorMessage {
  61. return FormatErrorAt(err.Point, err.Desc())
  62. }
  63. func (err *TypeError) Error() string {
  64. var msg = MsgFailedToCompile(err.Concrete, []ErrorMessage {
  65. err.Message(),
  66. })
  67. return msg.String()
  68. }
  69. type TypeDeclError struct {
  70. Point ErrorPoint
  71. Concrete ConcreteTypeDeclError
  72. }
  73. type ConcreteTypeDeclError interface { TypeDeclError() }
  74. func (impl E_InvalidTypeName) TypeDeclError() {}
  75. type E_InvalidTypeName struct {
  76. Name string
  77. }
  78. func (impl E_DuplicateTypeDecl) TypeDeclError() {}
  79. type E_DuplicateTypeDecl struct {
  80. TypeName loader.Symbol
  81. }
  82. func (impl E_GenericUnionSubType) TypeDeclError() {}
  83. type E_GenericUnionSubType struct {
  84. TypeName loader.Symbol
  85. }
  86. func (impl E_InvalidTypeDecl) TypeDeclError() {}
  87. type E_InvalidTypeDecl struct {
  88. TypeName loader.Symbol
  89. Detail *TypeError
  90. }
  91. func (err *TypeDeclError) Desc() ErrorMessage {
  92. var msg = make(ErrorMessage, 0)
  93. switch e := err.Concrete.(type) {
  94. case E_InvalidTypeName:
  95. msg.WriteText(TS_ERROR, "Invalid type name:")
  96. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  97. case E_DuplicateTypeDecl:
  98. msg.WriteText(TS_ERROR, "Duplicate type declaration:")
  99. msg.WriteEndText(TS_INLINE_CODE, e.TypeName.SymbolName)
  100. case E_GenericUnionSubType:
  101. msg.WriteText(TS_ERROR, "Cannot define generic parameters on a union item")
  102. case E_InvalidTypeDecl:
  103. msg = e.Detail.Desc()
  104. default:
  105. panic("unknown error kind")
  106. }
  107. return msg
  108. }
  109. func (err *TypeDeclError) Message() ErrorMessage {
  110. return FormatErrorAt(err.Point, err.Desc())
  111. }
  112. func (err *TypeDeclError) Error() string {
  113. var msg = MsgFailedToCompile(err.Concrete, []ErrorMessage {
  114. err.Message(),
  115. })
  116. return msg.String()
  117. }
  118. type FunctionError struct {
  119. Point ErrorPoint
  120. Concrete ConcreteFunctionError
  121. }
  122. type ConcreteFunctionError interface { FunctionError() }
  123. func (impl E_InvalidFunctionName) FunctionError() {}
  124. type E_InvalidFunctionName struct {
  125. Name string
  126. }
  127. func (impl E_SignatureInvalid) FunctionError() {}
  128. type E_SignatureInvalid struct {
  129. FuncName string
  130. TypeError *TypeError
  131. }
  132. func (E_SignatureNonLocal) FunctionError() {}
  133. type E_SignatureNonLocal struct {
  134. FuncName string
  135. }
  136. func (E_InvalidOverload) FunctionError() {}
  137. type E_InvalidOverload struct {
  138. BetweenLocal bool
  139. AddedName string
  140. AddedModule string
  141. AddedType string
  142. ExistingType string
  143. }
  144. func (err *FunctionError) Desc() ErrorMessage {
  145. var msg = make(ErrorMessage, 0)
  146. switch e := err.Concrete.(type) {
  147. case E_InvalidFunctionName:
  148. msg.WriteText(TS_ERROR, "Invalid function name")
  149. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  150. case E_SignatureInvalid:
  151. msg = e.TypeError.Desc()
  152. case E_SignatureNonLocal:
  153. msg.WriteText(TS_ERROR, "Function")
  154. msg.WriteInnerText(TS_INLINE_CODE, e.FuncName)
  155. msg.WriteText(TS_ERROR, "is declared to be public but has a non-local signature type")
  156. case E_InvalidOverload:
  157. msg.WriteText(TS_ERROR, "Cannot overload this function instance with the signature")
  158. msg.WriteInnerText(TS_INLINE_CODE, e.AddedType)
  159. msg.WriteText(TS_ERROR, "on the function name")
  160. msg.WriteInnerText(TS_INLINE_CODE, e.AddedName)
  161. msg.WriteText(TS_ERROR, "since a function with conflicting signature")
  162. msg.WriteInnerText(TS_INLINE_CODE, e.ExistingType)
  163. msg.WriteText(TS_ERROR, "already exists")
  164. if e.BetweenLocal {
  165. msg.WriteEndText(TS_ERROR, "in the current module")
  166. } else {
  167. msg.WriteInnerText(TS_ERROR, "in the module")
  168. msg.WriteText(TS_INLINE_CODE, e.AddedModule)
  169. }
  170. default:
  171. panic("unknown error kind")
  172. }
  173. return msg
  174. }
  175. func (err *FunctionError) Message() ErrorMessage {
  176. return FormatErrorAt(err.Point, err.Desc())
  177. }
  178. func (err *FunctionError) Error() string {
  179. var msg = MsgFailedToCompile(err.Concrete, []ErrorMessage {
  180. err.Message(),
  181. })
  182. return msg.String()
  183. }
  184. type ConstantError struct {
  185. Point ErrorPoint
  186. Concrete ConcreteConstantError
  187. }
  188. type ConcreteConstantError interface { ConstantError() }
  189. func (impl E_InvalidConstName) ConstantError() {}
  190. type E_InvalidConstName struct {
  191. Name string
  192. }
  193. func (impl E_DuplicateConstDecl) ConstantError() {}
  194. type E_DuplicateConstDecl struct {
  195. Name string
  196. }
  197. func (impl E_ConstTypeInvalid) ConstantError() {}
  198. type E_ConstTypeInvalid struct {
  199. ConstName string
  200. TypeError *TypeError
  201. }
  202. func (impl E_ConstConflictWithType) ConstantError() {}
  203. type E_ConstConflictWithType struct {
  204. Name string
  205. }
  206. func (err *ConstantError) Desc() ErrorMessage {
  207. var msg = make(ErrorMessage, 0)
  208. switch e := err.Concrete.(type) {
  209. case E_InvalidConstName:
  210. msg.WriteText(TS_ERROR, "Invalid constant name")
  211. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  212. case E_DuplicateConstDecl:
  213. msg.WriteText(TS_ERROR, "Duplicate declaration of constant")
  214. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  215. case E_ConstTypeInvalid:
  216. msg = e.TypeError.Desc()
  217. case E_ConstConflictWithType:
  218. msg.WriteText(TS_ERROR, "The constant name")
  219. msg.WriteInnerText(TS_INLINE_CODE, e.Name)
  220. msg.WriteText(TS_ERROR, "conflict with existing type name")
  221. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  222. default:
  223. panic("unknown error kind")
  224. }
  225. return msg
  226. }
  227. func (err *ConstantError) Message() ErrorMessage {
  228. return FormatErrorAt(err.Point, err.Desc())
  229. }
  230. func (err *ConstantError) Error() string {
  231. var msg = MsgFailedToCompile(err.Concrete, []ErrorMessage {
  232. err.Message(),
  233. })
  234. return msg.String()
  235. }
  236. type ExprError struct {
  237. Point ErrorPoint
  238. Concrete ConcreteExprError
  239. }
  240. type ConcreteExprError interface {
  241. ExprErrorDesc() ErrorMessage
  242. }
  243. type E_InvalidInteger struct {
  244. Value string
  245. }
  246. func (e E_InvalidInteger) ExprErrorDesc() ErrorMessage {
  247. var msg = make(ErrorMessage, 0)
  248. msg.WriteText(TS_ERROR, "Invalid integer literal")
  249. msg.WriteEndText(TS_INLINE_CODE, e.Value)
  250. return msg
  251. }
  252. type E_ExprDuplicateField struct {
  253. Name string
  254. }
  255. func (e E_ExprDuplicateField) ExprErrorDesc() ErrorMessage {
  256. var msg = make(ErrorMessage, 0)
  257. msg.WriteText(TS_ERROR, "Duplicate field")
  258. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  259. return msg
  260. }
  261. type E_GetFromNonBundle struct {}
  262. func (e E_GetFromNonBundle) ExprErrorDesc() ErrorMessage {
  263. var msg = make(ErrorMessage, 0)
  264. msg.WriteText(TS_ERROR,
  265. "Cannot perform field access on a value of non-bundle type")
  266. return msg
  267. }
  268. type E_GetFromLiteralBundle struct {}
  269. func (e E_GetFromLiteralBundle) ExprErrorDesc() ErrorMessage {
  270. var msg = make(ErrorMessage, 0)
  271. msg.WriteText(TS_ERROR, "Suspicious field access on bundle literal")
  272. return msg
  273. }
  274. type E_GetFromOpaqueBundle struct {}
  275. func (e E_GetFromOpaqueBundle) ExprErrorDesc() ErrorMessage {
  276. var msg = make(ErrorMessage, 0)
  277. msg.WriteText(TS_ERROR,
  278. "Cannot perform field access on a value of opaque bundle type")
  279. return msg
  280. }
  281. type E_SetToNonBundle struct {}
  282. func (e E_SetToNonBundle) ExprErrorDesc() ErrorMessage {
  283. var msg = make(ErrorMessage, 0)
  284. msg.WriteText(TS_ERROR,
  285. "Cannot perform field update on a value of non-bundle type")
  286. return msg
  287. }
  288. type E_SetToLiteralBundle struct {}
  289. func (e E_SetToLiteralBundle) ExprErrorDesc() ErrorMessage {
  290. var msg = make(ErrorMessage, 0)
  291. msg.WriteText(TS_ERROR, "Suspicious field update on bundle literal")
  292. return msg
  293. }
  294. type E_SetToOpaqueBundle struct {}
  295. func (e E_SetToOpaqueBundle) ExprErrorDesc() ErrorMessage {
  296. var msg = make(ErrorMessage, 0)
  297. msg.WriteText(TS_ERROR,
  298. "Cannot perform field update on a value of opaque bundle type")
  299. return msg
  300. }
  301. type E_FieldDoesNotExist struct {
  302. Field string
  303. Target string
  304. }
  305. func (e E_FieldDoesNotExist) ExprErrorDesc() ErrorMessage {
  306. var msg = make(ErrorMessage, 0)
  307. msg.WriteText(TS_ERROR, "The field")
  308. msg.WriteInnerText(TS_INLINE_CODE, e.Field)
  309. msg.WriteText(TS_ERROR, "does not exist on the type")
  310. msg.WriteEndText(TS_INLINE_CODE, e.Target)
  311. return msg
  312. }
  313. type E_MissingField struct {
  314. Field string
  315. Type string
  316. }
  317. func (e E_MissingField) ExprErrorDesc() ErrorMessage {
  318. var msg = make(ErrorMessage, 0)
  319. msg.WriteText(TS_ERROR, "Missing the field")
  320. msg.WriteInnerText(TS_INLINE_CODE, e.Field)
  321. msg.WriteText(TS_ERROR, "(type: ")
  322. msg.WriteText(TS_INLINE_CODE, e.Type)
  323. msg.WriteText(TS_ERROR, ")")
  324. return msg
  325. }
  326. type E_SurplusField struct {
  327. Field string
  328. }
  329. func (e E_SurplusField) ExprErrorDesc() ErrorMessage {
  330. var msg = make(ErrorMessage, 0)
  331. msg.WriteText(TS_ERROR, "Surplus field")
  332. msg.WriteEndText(TS_INLINE_CODE, e.Field)
  333. return msg
  334. }
  335. type E_EntireValueIgnored struct {}
  336. func (e E_EntireValueIgnored) ExprErrorDesc() ErrorMessage {
  337. var msg = make(ErrorMessage, 0)
  338. msg.WriteText(TS_ERROR, "Entire value ignored suspiciously")
  339. return msg
  340. }
  341. type E_TupleSizeNotMatching struct {
  342. Required int
  343. Given int
  344. GivenType string
  345. }
  346. func (e E_TupleSizeNotMatching) ExprErrorDesc() ErrorMessage {
  347. var msg = make(ErrorMessage, 0)
  348. msg.WriteText(TS_ERROR, "Tuple size not matching:")
  349. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Required))
  350. msg.WriteText(TS_ERROR, "required but")
  351. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Given))
  352. msg.WriteText(TS_ERROR, "given (expected type: ")
  353. msg.WriteText(TS_INLINE_CODE, e.GivenType)
  354. msg.WriteText(TS_ERROR, ")")
  355. return msg
  356. }
  357. type E_NotAssignable struct {
  358. From string
  359. To string
  360. Reason string
  361. }
  362. func (e E_NotAssignable) ExprErrorDesc() ErrorMessage {
  363. var msg = make(ErrorMessage, 0)
  364. msg.WriteText(TS_ERROR, "The value of type")
  365. msg.WriteInnerText(TS_INLINE_CODE, e.From)
  366. msg.WriteText(TS_ERROR, "cannot be assigned to the type")
  367. msg.WriteEndText(TS_INLINE_CODE, e.To)
  368. if e.Reason != "" {
  369. msg.WriteText(TS_ERROR, " (")
  370. msg.WriteText(TS_ERROR, e.Reason)
  371. msg.WriteText(TS_ERROR, ")")
  372. }
  373. return msg
  374. }
  375. type E_ExplicitTypeRequired struct {}
  376. func (e E_ExplicitTypeRequired) ExprErrorDesc() ErrorMessage {
  377. var msg = make(ErrorMessage, 0)
  378. msg.WriteText(TS_ERROR, "Explicit type cast desired")
  379. return msg
  380. }
  381. type E_DuplicateBinding struct {
  382. ValueName string
  383. }
  384. func (e E_DuplicateBinding) ExprErrorDesc() ErrorMessage {
  385. var msg = make(ErrorMessage, 0)
  386. msg.WriteText(TS_ERROR, "Duplicate binding of value name")
  387. msg.WriteEndText(TS_INLINE_CODE, e.ValueName)
  388. return msg
  389. }
  390. type E_MatchingNonTupleType struct {}
  391. func (e E_MatchingNonTupleType) ExprErrorDesc() ErrorMessage {
  392. var msg = make(ErrorMessage, 0)
  393. msg.WriteText(TS_ERROR,
  394. "Cannot perform tuple destruction on a value of non-tuple type")
  395. return msg
  396. }
  397. type E_MatchingOpaqueTupleType struct {}
  398. func (e E_MatchingOpaqueTupleType) ExprErrorDesc() ErrorMessage {
  399. var msg = make(ErrorMessage, 0)
  400. msg.WriteText(TS_ERROR,
  401. "Cannot perform tuple destruction on a value of opaque tuple type")
  402. return msg
  403. }
  404. type E_MatchingNonBundleType struct {}
  405. func (e E_MatchingNonBundleType) ExprErrorDesc() ErrorMessage {
  406. var msg = make(ErrorMessage, 0)
  407. msg.WriteText(TS_ERROR,
  408. "Cannot perform tuple destruction on a value of non-bundle type")
  409. return msg
  410. }
  411. type E_MatchingOpaqueBundleType struct {}
  412. func (e E_MatchingOpaqueBundleType) ExprErrorDesc() ErrorMessage {
  413. var msg = make(ErrorMessage, 0)
  414. msg.WriteText(TS_ERROR,
  415. "Cannot perform tuple destruction on a value of opaque bundle type")
  416. return msg
  417. }
  418. type E_LambdaAssignedToNonFuncType struct {
  419. NonFuncType string
  420. }
  421. func (e E_LambdaAssignedToNonFuncType) ExprErrorDesc() ErrorMessage {
  422. var msg = make(ErrorMessage, 0)
  423. msg.WriteText(TS_ERROR, "Cannot assign lambda to the non-function type")
  424. msg.WriteEndText(TS_INLINE_CODE, e.NonFuncType)
  425. return msg
  426. }
  427. type E_IntegerAssignedToNonIntegerType struct {
  428. NonIntegerType string
  429. }
  430. func (e E_IntegerAssignedToNonIntegerType) ExprErrorDesc() ErrorMessage {
  431. var msg = make(ErrorMessage, 0)
  432. msg.WriteText(TS_ERROR,
  433. "Cannot assign integer literal to the non-integer type")
  434. msg.WriteEndText(TS_INLINE_CODE, e.NonIntegerType)
  435. return msg
  436. }
  437. type E_IntegerOverflow struct {
  438. Kind string
  439. }
  440. func (e E_IntegerOverflow) ExprErrorDesc() ErrorMessage {
  441. var msg = make(ErrorMessage, 0)
  442. msg.WriteText(TS_ERROR, "Integer literal overflows")
  443. msg.WriteEndText(TS_INLINE, e.Kind)
  444. return msg
  445. }
  446. type E_TupleAssignedToNonTupleType struct {
  447. NonTupleType string
  448. }
  449. func (e E_TupleAssignedToNonTupleType) ExprErrorDesc() ErrorMessage {
  450. var msg = make(ErrorMessage, 0)
  451. msg.WriteText(TS_ERROR,
  452. "Cannot assign tuple literal to the non-tuple type")
  453. msg.WriteEndText(TS_INLINE_CODE, e.NonTupleType)
  454. return msg
  455. }
  456. type E_BundleAssignedToNonBundleType struct {
  457. NonBundleType string
  458. }
  459. func (e E_BundleAssignedToNonBundleType) ExprErrorDesc() ErrorMessage {
  460. var msg = make(ErrorMessage, 0)
  461. msg.WriteText(TS_ERROR,
  462. "Cannot assign bundle literal to the non-bundle type")
  463. msg.WriteEndText(TS_INLINE_CODE, e.NonBundleType)
  464. return msg
  465. }
  466. type E_ArrayAssignedToNonArrayType struct {
  467. NonArrayType string
  468. }
  469. func (e E_ArrayAssignedToNonArrayType) ExprErrorDesc() ErrorMessage {
  470. var msg = make(ErrorMessage, 0)
  471. msg.WriteText(TS_ERROR,
  472. "Cannot assign array literal to the non-array type")
  473. msg.WriteEndText(TS_INLINE_CODE, e.NonArrayType)
  474. return msg
  475. }
  476. type E_RecursiveMarkUsedOnNonLambda struct {}
  477. func (e E_RecursiveMarkUsedOnNonLambda) ExprErrorDesc() ErrorMessage {
  478. var msg = make(ErrorMessage, 0)
  479. msg.WriteText(TS_ERROR, "Invalid usage of recursion mark")
  480. return msg
  481. }
  482. type E_TypeErrorInExpr struct {
  483. TypeError *TypeError
  484. }
  485. func (e E_TypeErrorInExpr) ExprErrorDesc() ErrorMessage {
  486. return e.TypeError.Desc()
  487. }
  488. type E_InvalidMatchArgType struct {
  489. ArgType string
  490. }
  491. func (e E_InvalidMatchArgType) ExprErrorDesc() ErrorMessage {
  492. var msg = make(ErrorMessage, 0)
  493. msg.WriteText(TS_ERROR, "Cannot pattern match on the value of type")
  494. msg.WriteEndText(TS_INLINE_CODE, e.ArgType)
  495. return msg
  496. }
  497. type E_DuplicateDefaultBranch struct {}
  498. func (e E_DuplicateDefaultBranch) ExprErrorDesc() ErrorMessage {
  499. var msg = make(ErrorMessage, 0)
  500. msg.WriteText(TS_ERROR, "Duplicate default branch")
  501. return msg
  502. }
  503. type E_TypeParametersUnnecessary struct {}
  504. func (e E_TypeParametersUnnecessary) ExprErrorDesc() ErrorMessage {
  505. var msg = make(ErrorMessage, 0)
  506. msg.WriteText(TS_ERROR, "Unnecessary type parameters")
  507. return msg
  508. }
  509. type E_NotBranchType struct {
  510. Union string
  511. TypeName string
  512. }
  513. func (e E_NotBranchType) ExprErrorDesc() ErrorMessage {
  514. var msg = make(ErrorMessage, 0)
  515. msg.WriteText(TS_ERROR, "The type")
  516. msg.WriteInnerText(TS_INLINE_CODE, e.TypeName)
  517. msg.WriteText(TS_ERROR, "is not a branch type of the union type")
  518. msg.WriteEndText(TS_INLINE_CODE, e.Union)
  519. return msg
  520. }
  521. type E_IncompleteMatch struct {
  522. Missing [] string
  523. }
  524. func (e E_IncompleteMatch) ExprErrorDesc() ErrorMessage {
  525. var msg = make(ErrorMessage, 0)
  526. msg.WriteText(TS_ERROR,
  527. "Pattern matching is not exhaustive: missing branches ")
  528. for i, branch := range e.Missing {
  529. msg.WriteText(TS_INLINE_CODE, branch)
  530. if i != len(e.Missing)-1 {
  531. msg.WriteText(TS_ERROR, ", ")
  532. }
  533. }
  534. return msg
  535. }
  536. type E_NonBooleanCondition struct {
  537. Typed bool
  538. Type string
  539. }
  540. func (e E_NonBooleanCondition) ExprErrorDesc() ErrorMessage {
  541. var msg = make(ErrorMessage, 0)
  542. msg.WriteText(TS_ERROR,
  543. "Given condition expression has non-boolean type")
  544. if e.Typed {
  545. msg.WriteEndText(TS_INLINE_CODE, e.Type)
  546. }
  547. return msg
  548. }
  549. type E_ModuleNotFound struct {
  550. Name string
  551. }
  552. func (e E_ModuleNotFound) ExprErrorDesc() ErrorMessage {
  553. var msg = make(ErrorMessage, 0)
  554. msg.WriteText(TS_ERROR, "No such module:")
  555. msg.WriteEndText(TS_INLINE_CODE, e.Name)
  556. return msg
  557. }
  558. type E_TypeOrValueNotFound struct {
  559. Symbol loader.Symbol
  560. }
  561. func (e E_TypeOrValueNotFound) ExprErrorDesc() ErrorMessage {
  562. var msg = make(ErrorMessage, 0)
  563. msg.WriteText(TS_ERROR, "No such value or type:")
  564. msg.WriteEndText(TS_INLINE_CODE, e.Symbol.String())
  565. return msg
  566. }
  567. type E_TypeParamInExpr struct {
  568. Name string
  569. }
  570. func (e E_TypeParamInExpr) ExprErrorDesc() ErrorMessage {
  571. var msg = make(ErrorMessage, 0)
  572. msg.WriteText(TS_ERROR, "Cannot use type parameter")
  573. msg.WriteInnerText(TS_INLINE_CODE, e.Name)
  574. msg.WriteText(TS_ERROR, "as a value")
  575. return msg
  576. }
  577. type E_ExplicitTypeParamsRequired struct {}
  578. func (e E_ExplicitTypeParamsRequired) ExprErrorDesc() ErrorMessage {
  579. var msg = make(ErrorMessage, 0)
  580. msg.WriteText(TS_ERROR, "Explicit type parameters expected")
  581. return msg
  582. }
  583. type E_TypeUsedAsValue struct {
  584. TypeName loader.Symbol
  585. }
  586. func (e E_TypeUsedAsValue) ExprErrorDesc() ErrorMessage {
  587. var msg = make(ErrorMessage, 0)
  588. msg.WriteText(TS_ERROR, "Cannot use type")
  589. msg.WriteInnerText(TS_INLINE_CODE, e.TypeName.String())
  590. msg.WriteText(TS_ERROR, "as a value")
  591. return msg
  592. }
  593. type E_FunctionWrongTypeParamsQuantity struct {
  594. FuncName string
  595. Given uint
  596. Required uint
  597. }
  598. func (e E_FunctionWrongTypeParamsQuantity) ExprErrorDesc() ErrorMessage {
  599. var msg = make(ErrorMessage, 0)
  600. msg.WriteText(TS_ERROR, "The function")
  601. msg.WriteInnerText(TS_INLINE_CODE, e.FuncName)
  602. msg.WriteText(TS_ERROR, "requires")
  603. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Required))
  604. msg.WriteText(TS_ERROR, "type parameters but")
  605. msg.WriteInnerText(TS_INLINE, fmt.Sprint(e.Given))
  606. msg.WriteText(TS_ERROR, "given")
  607. return msg
  608. }
  609. type E_NoneOfFunctionsAssignable struct {
  610. To string
  611. Candidates [] string
  612. }
  613. func (e E_NoneOfFunctionsAssignable) ExprErrorDesc() ErrorMessage {
  614. var msg = make(ErrorMessage, 0)
  615. msg.WriteText(TS_ERROR,
  616. "None of function instances assignable to the type")
  617. msg.WriteEndText(TS_INLINE_CODE, e.To)
  618. msg.Write(T_LF)
  619. msg.WriteText(TS_INFO, "*** candidates are:")
  620. msg.Write(T_LF)
  621. for _, candidate := range e.Candidates {
  622. msg.Write(T_INDENT)
  623. msg.WriteText(TS_INLINE_CODE, candidate)
  624. msg.Write(T_LF)
  625. }
  626. return msg
  627. }
  628. type E_NoneOfFunctionsCallable struct {
  629. Candidates [] string
  630. }
  631. func (e E_NoneOfFunctionsCallable) ExprErrorDesc() ErrorMessage {
  632. var msg = make(ErrorMessage, 0)
  633. msg.WriteText(TS_ERROR,
  634. "None of function instances can be called")
  635. msg.Write(T_LF)
  636. msg.WriteText(TS_INFO, "*** candidates are:")
  637. msg.Write(T_LF)
  638. for _, candidate := range e.Candidates {
  639. msg.Write(T_INDENT)
  640. msg.WriteText(TS_INLINE_CODE, candidate)
  641. msg.Write(T_LF)
  642. }
  643. return msg
  644. }
  645. type E_ExprNotCallable struct {}
  646. func (e E_ExprNotCallable) ExprErrorDesc() ErrorMessage {
  647. var msg = make(ErrorMessage, 0)
  648. msg.WriteText(TS_ERROR, "This value is not callable")
  649. return msg
  650. }
  651. type E_ExprTypeNotCallable struct {
  652. Type string
  653. }
  654. func (e E_ExprTypeNotCallable) ExprErrorDesc() ErrorMessage {
  655. var msg = make(ErrorMessage, 0)
  656. msg.WriteText(TS_ERROR, "This value is not callable: type")
  657. msg.WriteInnerText(TS_INLINE_CODE, e.Type)
  658. msg.WriteText(TS_ERROR, "is not callable")
  659. return msg
  660. }
  661. type E_NoneOfTypesAssignable struct {
  662. From [] string
  663. To string
  664. }
  665. func (e E_NoneOfTypesAssignable) ExprErrorDesc() ErrorMessage {
  666. var msg = make(ErrorMessage, 0)
  667. msg.WriteText(TS_ERROR, "Cannot assign to type")
  668. msg.WriteInnerText(TS_INLINE_CODE, e.To)
  669. msg.WriteText(TS_ERROR, "from any of available return types: ")
  670. for i, item := range e.From {
  671. msg.WriteText(TS_INLINE_CODE, item)
  672. if i != len(e.From)-1 {
  673. msg.WriteText(TS_ERROR, ", ")
  674. }
  675. }
  676. return msg
  677. }
  678. type E_BoxNonBoxedType struct {
  679. Type string
  680. }
  681. func (e E_BoxNonBoxedType) ExprErrorDesc() ErrorMessage {
  682. var msg = make(ErrorMessage, 0)
  683. msg.WriteText(TS_ERROR, "Cannot box a value into the non-boxed type")
  684. msg.WriteEndText(TS_INLINE_CODE, e.Type)
  685. return msg
  686. }
  687. type E_BoxProtectedType struct {
  688. Type string
  689. }
  690. func (e E_BoxProtectedType) ExprErrorDesc() ErrorMessage {
  691. var msg = make(ErrorMessage, 0)
  692. msg.WriteText(TS_ERROR, "Cannot box a value into the protected type")
  693. msg.WriteEndText(TS_INLINE_CODE, e.Type)
  694. return msg
  695. }
  696. type E_BoxOpaqueType struct {
  697. Type string
  698. }
  699. func (e E_BoxOpaqueType) ExprErrorDesc() ErrorMessage {
  700. var msg = make(ErrorMessage, 0)
  701. msg.WriteText(TS_ERROR, "Cannot box a value into the opaque type")
  702. msg.WriteEndText(TS_INLINE_CODE, e.Type)
  703. return msg
  704. }
  705. func (err *ExprError) Desc() ErrorMessage {
  706. return err.Concrete.ExprErrorDesc()
  707. }
  708. func (err *ExprError) Message() ErrorMessage {
  709. return FormatErrorAt(err.Point, err.Desc())
  710. }
  711. func (err *ExprError) Error() string {
  712. var msg = MsgFailedToCompile(err.Concrete, []ErrorMessage {
  713. err.Message(),
  714. })
  715. return msg.String()
  716. }