Skip to content

Feature Request: Support InlineArray type sugar #978

Open
@kkebo

Description

@kkebo

Summary

Swift can use experimental type sugar for InlineArray (e.g. [3 x Int]), and swift-syntax already has supported it, but swift-format hasn't supported it yet.

Input

test.swift:

let a: [3 x Int] = [1, 2, 3]

Expected result

let a: [3 x Int] = [1, 2, 3]

Actual result

(with --enable-experimental-feature InlineArrayTypeSugar)

let a: [3xInt] = [1, 2, 3]

However, this result causes compiler errrors.

$ swift-format format --enable-experimental-feature InlineArrayTypeSugar -i test.swift
$ swiftc -enable-experimental-feature InlineArrayTypeSugar test.swift
test.swift:1:10: error: 'x' is not a valid digit in integer literal
1 | let a: [3xInt] = [1, 2, 3]
  |          `- error: 'x' is not a valid digit in integer literal
2 | 

test.swift:1:9: error: expected element type
1 | let a: [3xInt] = [1, 2, 3]
  |         `- error: expected element type
2 | 

test.swift:1:9: error: expected ']' in array type
1 | let a: [3xInt] = [1, 2, 3]
  |        |`- error: expected ']' in array type
  |        `- note: to match this opening '['
2 | 

test.swift:1:14: error: consecutive statements on a line must be separated by ';'
1 | let a: [3xInt] = [1, 2, 3]
  |              `- error: consecutive statements on a line must be separated by ';'
2 | 

test.swift:1:14: error: expected expression
1 | let a: [3xInt] = [1, 2, 3]
  |              `- error: expected expression
2 | 

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions