-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.tl
More file actions
123 lines (100 loc) · 3.13 KB
/
Copy pathexample.tl
File metadata and controls
123 lines (100 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
-- vim: fdm=marker
-- vim: set colorcolumn=85
--local record Vector1
--x: number
--end
--local record Vector2
----embed Vector1
--y: number
--end
--[[
local type Pipeline = record
new: function(): Pipeline
-- Вход в секцию отправки
enter: function(Pipeline)
-- Затолкать данные в канал
push: function(Pipeline, any)
-- Завершение секции отправки
leave: function(Pipeline)
end
--]]
-- Не ловится ошибка, что отсутствует реализация Pipeline.new()
-- Компиляция успешная, падение происходит во время выполнения.
--local pipeline = Pipeline.new()
--[[
function get_foos<T>():{T}
return {}
end
--]]
--[[
function get_foos():{integer}
return {}
end
--local foos:{integer} = get_foos()
local foos:{integer} = get_foos()
print(foos)
--]]
--[[
local record Some
func1: function();
func2: function();
end
--]]
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Идеи по лучшему сообщению об ошибке такого рода.
--[[
local enum Command
"circle"
"line"
"rect"
end
local commands = {}
function commands.circle(_: string)
end
function commands.line(_: number)
end
function commands.rect(_: integer)
end
local cmd: Command = 'circle'
commands[cmd]()
--]]
-- Текущее сообщение об ошибке:
--1 error:
--example.tl:71:10: cannot index, not all enum values map to record fields of the same type
-- Предложение:
-- Показывать первое несоответствие одного типа другому.
--example.tl:71:10: cannot index, not all enum values map to record fields of the same type( function(string) ~= function(number) )
-- Предложение по реализации:
--[[
return match_all_record_field_names(idxnode, a, field_names,
"cannot index, not all enum values map to record fields of the same type( <f> ~= <t>)")
--]]
--[[
local function match_all_record_field_names(node: Node, a: Type, field_names: {string}, errmsg: string): Type
local t: Type
for _, k in ipairs(field_names) do
local f = a.fields[k]
if not t then
t = f
else
if not same_type(f, t) then
t = nil
break
end
end
end
if t then
return t
else
-- using string.gsub() for templating errmsg
return node_error(node, errmsg)
end
end
--]]
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------
------------------------------------------------------------------------------