@@ -187,10 +187,11 @@ f(arg) = arg
187
187
@test StaticLint. CoreTypes. ismodule (bindingof (parse_and_pass (" module A end" ). args[1 ]). type)
188
188
@test StaticLint. CoreTypes. ismodule (bindingof (parse_and_pass (" baremodule A end" ). args[1 ]). type)
189
189
190
- # @test parse_and_pass("function f(x::Int) x end")[1][2][3].binding.t == StaticLint.getsymbolserver(server)["Core"].vals["Function"]
190
+ # @test parse_and_pass("function f(x::Int) x end")[1][2][3].binding.t == StaticLint.getsymbolserver(server)["Core"].vals["Function"]
191
191
let cst = parse_and_pass ("""
192
192
struct T end
193
- function f(x::T) x end""" )
193
+ function f(x::T) x end
194
+ """ )
194
195
@test StaticLint. CoreTypes. isdatatype (bindingof (cst. args[1 ]). type)
195
196
@test StaticLint. CoreTypes. isfunction (bindingof (cst. args[2 ]). type)
196
197
@test bindingof (cst. args[2 ]. args[1 ]. args[2 ]). type == bindingof (cst. args[1 ])
@@ -199,7 +200,8 @@ f(arg) = arg
199
200
let cst = parse_and_pass ("""
200
201
struct T end
201
202
T() = 1
202
- function f(x::T) x end""" )
203
+ function f(x::T) x end
204
+ """ )
203
205
@test StaticLint. CoreTypes. isdatatype (bindingof (cst. args[1 ]). type)
204
206
@test StaticLint. CoreTypes. isfunction (bindingof (cst. args[3 ]). type)
205
207
@test bindingof (cst. args[3 ]. args[1 ]. args[2 ]). type == bindingof (cst. args[1 ])
@@ -208,7 +210,8 @@ f(arg) = arg
208
210
209
211
let cst = parse_and_pass ("""
210
212
struct T end
211
- t = T()""" )
213
+ t = T()
214
+ """ )
212
215
@test StaticLint. CoreTypes. isdatatype (bindingof (cst. args[1 ]). type)
213
216
@test bindingof (cst. args[2 ]. args[1 ]). type == bindingof (cst. args[1 ])
214
217
end
@@ -222,7 +225,8 @@ f(arg) = arg
222
225
import ..B
223
226
B.x
224
227
end
225
- end""" )
228
+ end
229
+ """ )
226
230
@test refof (cst. args[1 ]. args[3 ]. args[2 ]. args[3 ]. args[2 ]. args[2 ]. args[1 ]) == bindingof (cst[1 ]. args[3 ]. args[1 ]. args[3 ]. args[1 ]. args[1 ])
227
231
end
228
232
@@ -235,7 +239,8 @@ f(arg) = arg
235
239
end
236
240
function f(arg::T1)
237
241
arg.field.x
238
- end""" );
242
+ end
243
+ """ );
239
244
@test refof (cst. args[3 ]. args[2 ]. args[1 ]. args[1 ]. args[1 ]) == bindingof (cst. args[3 ]. args[1 ]. args[2 ])
240
245
@test refof (cst. args[3 ]. args[2 ]. args[1 ]. args[1 ]. args[2 ]. args[1 ]) == bindingof (cst. args[2 ]. args[3 ]. args[1 ])
241
246
@test refof (cst. args[3 ]. args[2 ]. args[1 ]. args[2 ]. args[1 ]) == bindingof (cst. args[1 ]. args[3 ]. args[1 ])
@@ -246,9 +251,9 @@ f(arg) = arg
246
251
end
247
252
248
253
let cst = parse_and_pass ("""
249
- macro mac_str() end
250
- mac"whatever"
251
- """ )
254
+ macro mac_str() end
255
+ mac"whatever"
256
+ """ )
252
257
@test refof (cst. args[2 ]. args[1 ]) == bindingof (cst. args[1 ])
253
258
end
254
259
@@ -261,50 +266,50 @@ f(arg) = arg
261
266
end
262
267
263
268
let cst = parse_and_pass ("""
264
- module Reparse
265
- end
266
- using .Reparse, CSTParser
267
- """ )
269
+ module Reparse
270
+ end
271
+ using .Reparse, CSTParser
272
+ """ )
268
273
@test refof (cst. args[2 ]. args[1 ]. args[2 ]). val == bindingof (cst[1 ])
269
274
end
270
275
271
276
let cst = parse_and_pass ("""
272
- module A
273
- A
274
- end
275
- """ )
277
+ module A
278
+ A
279
+ end
280
+ """ )
276
281
@test scopeof (cst). names[" A" ] == scopeof (cst. args[1 ]). names[" A" ]
277
282
@test refof (cst. args[1 ]. args[2 ]) == bindingof (cst. args[1 ])
278
283
@test refof (cst. args[1 ]. args[3 ]. args[1 ]) == bindingof (cst. args[1 ])
279
284
end
280
- # let cst = parse_and_pass("""
281
- # using Test: @test
282
- # """)
283
- # @test bindingof(cst[1][4]) !== nothing
284
- # end
285
+ # let cst = parse_and_pass("""
286
+ # using Test: @test
287
+ # """)
288
+ # @test bindingof(cst[1][4]) !== nothing
289
+ # end
285
290
let cst = parse_and_pass ("""
286
- sin(1,2,3)
287
- """ )
291
+ sin(1,2,3)
292
+ """ )
288
293
@test errorof (cst. args[1 ]) === StaticLint. IncorrectCallArgs
289
294
end
290
295
let cst = parse_and_pass ("""
291
- for i in length(1) end
292
- for i in 1.1 end
293
- for i in 1 end
294
- for i in 1:1 end
295
- """ )
296
+ for i in length(1) end
297
+ for i in 1.1 end
298
+ for i in 1 end
299
+ for i in 1:1 end
300
+ """ )
296
301
@test errorof (cst. args[1 ]. args[1 ]) === StaticLint. IncorrectIterSpec
297
302
@test errorof (cst. args[2 ]. args[1 ]) === StaticLint. IncorrectIterSpec
298
303
@test errorof (cst. args[3 ]. args[1 ]) === StaticLint. IncorrectIterSpec
299
304
@test errorof (cst. args[4 ]. args[1 ]) === nothing
300
305
end
301
306
302
307
let cst = parse_and_pass ("""
303
- [i for i in length(1) end]
304
- [i for i in 1.1 end]
305
- [i for i in 1 end]
306
- [i for i in 1:1 end]
307
- """ )
308
+ [i for i in length(1) end]
309
+ [i for i in 1.1 end]
310
+ [i for i in 1 end]
311
+ [i for i in 1:1 end]
312
+ """ )
308
313
@test errorof (cst[1 ][2 ][3 ]) === StaticLint. IncorrectIterSpec
309
314
@test errorof (cst[2 ][2 ][3 ]) === StaticLint. IncorrectIterSpec
310
315
@test errorof (cst[3 ][2 ][3 ]) === StaticLint. IncorrectIterSpec
@@ -319,29 +324,44 @@ f(arg) = arg
319
324
end
320
325
321
326
let cst = parse_and_pass ("""
322
- struct Graph
323
- children:: T
324
- end
327
+ struct Graph
328
+ children:: T
329
+ end
325
330
326
- function test()
327
- g = Graph()
328
- f = g.children
329
- end""" )
331
+ function test()
332
+ g = Graph()
333
+ f = g.children
334
+ end""" )
330
335
@test cst. args[2 ]. args[2 ]. args[2 ]. args[2 ]. args[2 ]. args[1 ] in bindingof (cst. args[1 ]. args[3 ]. args[1 ]). refs
331
336
end
332
337
333
338
let cst = parse_and_pass ("""
334
- __source__
335
- __module__
336
- macro m()
337
- __source__
338
- __module__
339
- end""" )
339
+ __source__
340
+ __module__
341
+ macro m()
342
+ __source__
343
+ __module__
344
+ end""" )
340
345
@test refof (cst[1 ]) === nothing
341
346
@test refof (cst[2 ]) === nothing
342
347
@test refof (cst[3 ][3 ][1 ]) != = nothing
343
348
@test refof (cst[3 ][3 ][2 ]) != = nothing
344
349
end
350
+
351
+ let cst = parse_and_pass ("""
352
+ struct Foo
353
+ x::DataType
354
+ y::Float64
355
+ end
356
+ (;x, y) = Foo(1,2)
357
+ x
358
+ y
359
+ """ )
360
+ mx = cst. args[3 ]. meta
361
+ @test mx. ref. type. name. name. name == :DataType
362
+ my = cst. args[4 ]. meta
363
+ @test my. ref. type. name. name. name == :Float64
364
+ end
345
365
end
346
366
347
367
@testset " macros" begin
@@ -1351,9 +1371,13 @@ f(arg) = arg
1351
1371
@testset " issue 1609" begin
1352
1372
let
1353
1373
cst1 = parse_and_pass (" function g(@nospecialize(x), y) x + y end" )
1354
- cst2 = parse_and_pass (" function g(@nospecialize(x), y) y end" )
1374
+ cst2 = parse_and_pass (" function g(@nospecialize(x) = 1) x end" )
1375
+ cst3 = parse_and_pass (" function g(@nospecialize(x) = 1, y = 2) x + y end" )
1376
+ cst4 = parse_and_pass (" function g(@nospecialize(x), y) y end" )
1355
1377
@test ! StaticLint. haserror (cst1. args[1 ]. args[1 ]. args[2 ]. args[3 ])
1356
- @test StaticLint. haserror (cst2. args[1 ]. args[1 ]. args[2 ]. args[3 ])
1378
+ @test ! StaticLint. haserror (cst2. args[1 ]. args[1 ]. args[2 ]. args[1 ])
1379
+ @test ! StaticLint. haserror (cst3. args[1 ]. args[1 ]. args[2 ]. args[1 ])
1380
+ @test StaticLint. haserror (cst4. args[1 ]. args[1 ]. args[2 ]. args[3 ])
1357
1381
end
1358
1382
end
1359
1383
0 commit comments