File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 1355
1355
(list 'where (rewrap-where x (cadr w)) (caddr w))
1356
1356
x))
1357
1357
1358
+ (define (parse-struct-field s )
1359
+ (let ((tok (peek-token s)))
1360
+ ; ; allow `const x` only as a struct field
1361
+ (if (eq? tok 'const )
1362
+ (begin (take-token s)
1363
+ `(const ,(parse-eq s)))
1364
+ (parse-eq s))))
1365
+
1358
1366
(define (parse-struct-def s mut? word )
1359
1367
(if (reserved-word? (peek-token s))
1360
1368
(error (string " invalid type name \" " (take-token s) " \" " )))
1361
1369
(let ((sig (parse-subtype-spec s)))
1362
- (begin0 (list 'struct (if mut? ' (true) ' (false)) sig (parse-block s))
1370
+ (begin0 (list 'struct (if mut? ' (true) ' (false)) sig (parse-block s parse-struct-field ))
1363
1371
(expect-end s word))))
1364
1372
1365
1373
; ; consume any number of line endings from a token stream
1456
1464
`(const ,expr)
1457
1465
expr)))
1458
1466
((const)
1459
- `(const ,(parse-eq s)))
1467
+ (let ((assgn (parse-eq s)))
1468
+ (if (not (and (pair? assgn)
1469
+ (or (eq? (car assgn) '= )
1470
+ (eq? (car assgn) 'global )
1471
+ (eq? (car assgn) 'local ))))
1472
+ (error " expected assignment after \" const\" " )
1473
+ `(const ,assgn))))
1460
1474
1461
1475
((function macro)
1462
1476
(let* ((loc (line-number-node s))
Original file line number Diff line number Diff line change @@ -3278,3 +3278,13 @@ demo44723()::Any = Base.Experimental.@opaque () -> true ? 1 : 2
3278
3278
# issue #45162
3279
3279
f45162 (f) = f (x= 1 )
3280
3280
@test first (methods (f45162)). called != 0
3281
+
3282
+ # issue #45024
3283
+ @test_throws ParseError (" expected assignment after \" const\" " ) Meta. parse (" const x" )
3284
+ @test_throws ParseError (" expected assignment after \" const\" " ) Meta. parse (" const x::Int" )
3285
+ # these cases have always been caught during lowering, since (const (global x)) is not
3286
+ # ambiguous with the lowered form (const x), but that could probably be changed.
3287
+ @test Meta. lower (@__MODULE__ , :(global const x)) == Expr (:error , " expected assignment after \" const\" " )
3288
+ @test Meta. lower (@__MODULE__ , :(global const x:: Int )) == Expr (:error , " expected assignment after \" const\" " )
3289
+ @test Meta. lower (@__MODULE__ , :(const global x)) == Expr (:error , " expected assignment after \" const\" " )
3290
+ @test Meta. lower (@__MODULE__ , :(const global x:: Int )) == Expr (:error , " expected assignment after \" const\" " )
You can’t perform that action at this time.
0 commit comments