@@ -92,27 +92,27 @@ describe("Module", function()
9292 assert_error ([[
9393 function m.f() end
9494 function m.f() end
95- ]] , " multiple definitions for module field 'f'" )
95+ ]] , " the module field 'f' is being shadowed " )
9696 end )
9797
9898 it (" forbids repeated exported names (function / variable)" , function ()
9999 assert_error ([[
100100 function m.f() end
101101 m.f = 1
102- ]] , " multiple definitions for module field 'f'" )
102+ ]] , " the module field 'f' is being shadowed " )
103103 end )
104104
105105 it (" forbids repeated exported names (variable / variable)" , function ()
106106 assert_error ([[
107107 m.x = 10
108108 m.x = 20
109- ]] , " multiple definitions for module field 'x'" )
109+ ]] , " the module field 'x' is being shadowed " )
110110 end )
111111
112112 it (" forbids repeated exported names (in multiple assignment)" , function ()
113113 assert_error ([[
114114 m.x, m.x = 10, 20
115- ]] , " multiple definitions for module field 'x'" )
115+ ]] , " the module field 'x' is being shadowed " )
116116 end )
117117
118118 it (" ensures that exported variables are not in scope in their initializers" , function ()
@@ -142,6 +142,37 @@ describe("Typealias", function()
142142 ]] , " 't' is not a type" )
143143 end )
144144
145+ it (" must not be shadowed by other typealias names" , function ()
146+ assert_error ([[
147+ typealias point = {x: integer, y: integer}
148+ typealias point = {x: float, y: float}
149+ ]] , " the type 'point' is being shadowed" )
150+ end )
151+
152+ it (" must not be shadowed by record names" , function ()
153+ assert_error ([[
154+ typealias point = {x: float, y: float}
155+ record point
156+ x: integer
157+ y: integer
158+ end
159+ ]] , " the type 'point' is being shadowed" )
160+ end )
161+
162+ it (" must not be shadowed by module field names" , function ()
163+ assert_error ([[
164+ typealias x = integer
165+ m.x = 10
166+ ]] , " the type 'x' is being shadowed" )
167+ end )
168+
169+ it (" must not be shadowed by function names" , function ()
170+ assert_error ([[
171+ typealias f = integer
172+ function m.f() end
173+ ]] , " the type 'f' is being shadowed" )
174+ end )
175+
145176end )
146177
147178describe (" Record declaration" , function ()
@@ -155,6 +186,49 @@ describe("Record declaration", function()
155186 ]] , " duplicate field name 'x' in record type" )
156187 end )
157188
189+ it (" must not be shadowed by other record names" , function ()
190+ assert_error ([[
191+ record Point
192+ x: integer
193+ y: integer
194+ end
195+ record Point
196+ x: float
197+ y: float
198+ end
199+ ]] , " the type 'Point' is being shadowed" )
200+ end )
201+
202+ it (" must not be shadowed by typealias names" , function ()
203+ assert_error ([[
204+ record Point
205+ x: integer
206+ y: integer
207+ end
208+ typealias Point = {x: float, y: float}
209+ ]] , " the type 'Point' is being shadowed" )
210+ end )
211+
212+ it (" must not be shadowed by module field names" , function ()
213+ assert_error ([[
214+ record P
215+ x: integer
216+ y: integer
217+ end
218+ m.P = 10
219+ ]] , " the type 'P' is being shadowed" )
220+ end )
221+
222+ it (" must not be shadowed by function names" , function ()
223+ assert_error ([[
224+ record P
225+ x: integer
226+ y: integer
227+ end
228+ function m.P() end
229+ ]] , " the type 'P' is being shadowed" )
230+ end )
231+
158232end )
159233
160234describe (" Function declaration" , function ()
@@ -195,6 +269,71 @@ describe("Function declaration", function()
195269 ]] , " function 'f' was not forward declared" )
196270 end )
197271
272+ it (" must not be shadowed by typealias names" , function ()
273+ assert_error ([[
274+ function m.f() end
275+ typealias f = integer
276+ ]] , " the module field 'f' is being shadowed" )
277+ end )
278+
279+ it (" must not be shadowed by record names" , function ()
280+ assert_error ([[
281+ function m.f() end
282+ record f
283+ x: integer
284+ y: integer
285+ end
286+ ]] , " the module field 'f' is being shadowed" )
287+ end )
288+
289+ it (" must not be shadowed by module field names" , function ()
290+ assert_error ([[
291+ function m.f() end
292+ m.f = 10
293+ ]] , " the module field 'f' is being shadowed" )
294+ end )
295+
296+ it (" must not be shadowed by function names" , function ()
297+ assert_error ([[
298+ function m.f() end
299+ function m.f() end
300+ ]] , " the module field 'f' is being shadowed" )
301+ end )
302+
303+ end )
304+
305+ describe (" Module fields" , function ()
306+
307+ it (" must not be shadowed by typealias names" , function ()
308+ assert_error ([[
309+ m.x = 10
310+ typealias x = integer
311+ ]] , " the module field 'x' is being shadowed" )
312+ end )
313+
314+ it (" must not be shadowed by record names" , function ()
315+ assert_error ([[
316+ m.x = 10
317+ record x
318+ y: integer
319+ end
320+ ]] , " the module field 'x' is being shadowed" )
321+ end )
322+
323+ it (" must not be shadowed by function names" , function ()
324+ assert_error ([[
325+ m.f = 10
326+ function m.f() end
327+ ]] , " the module field 'f' is being shadowed" )
328+ end )
329+
330+ it (" must not be shadowed by module field names" , function ()
331+ assert_error ([[
332+ m.x = 10
333+ m.x = 20
334+ ]] , " the module field 'x' is being shadowed" )
335+ end )
336+
198337end )
199338
200339--
0 commit comments