Skip to content

Commit 493bf5d

Browse files
committed
Fix overrides of class(/static) methods
1 parent 1f83e4e commit 493bf5d

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

Sources/CSSOM/Generated.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,10 @@ public class CSSColorValue: CSSStyleValue {
396396
return this[Strings.to].function!(this: this, arguments: [_toJSValue(colorSpace)]).fromJSValue()!
397397
}
398398

399-
// XXX: illegal static override
400-
// override public class func parse(cssText: String) -> CSSColorValue_or_CSSStyleValue
399+
@inlinable override public class func parse(cssText: String) -> CSSColorValue_or_CSSStyleValue {
400+
let this = constructor!
401+
return this[Strings.parse].function!(this: this, arguments: [_toJSValue(cssText)]).fromJSValue()!
402+
}
401403
}
402404

403405
public class CSSGroupingRule: CSSRule {
@@ -951,8 +953,10 @@ public class CSSNumericValue: CSSStyleValue {
951953
return this[Strings.type].function!(this: this, arguments: []).fromJSValue()!
952954
}
953955

954-
// XXX: illegal static override
955-
// override public class func parse(cssText: String) -> Self
956+
@inlinable override public class func parse(cssText: String) -> Self {
957+
let this = constructor!
958+
return this[Strings.parse].function!(this: this, arguments: [_toJSValue(cssText)]).fromJSValue()!
959+
}
956960
}
957961

958962
public class CSSOKLCH: CSSColorValue {

Sources/DOM/Generated.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,14 +2769,20 @@ public class DOMMatrix: DOMMatrixReadOnly {
27692769
self.init(unsafelyWrapping: Self.constructor!.new(arguments: [_toJSValue(`init`)]))
27702770
}
27712771

2772-
// XXX: illegal static override
2773-
// override public class func fromMatrix(other: DOMMatrixInit? = nil) -> Self
2772+
@inlinable override public class func fromMatrix(other: DOMMatrixInit? = nil) -> Self {
2773+
let this = constructor!
2774+
return this[Strings.fromMatrix].function!(this: this, arguments: [_toJSValue(other)]).fromJSValue()!
2775+
}
27742776

2775-
// XXX: illegal static override
2776-
// override public class func fromFloat32Array(array32: Float32Array) -> Self
2777+
@inlinable override public class func fromFloat32Array(array32: Float32Array) -> Self {
2778+
let this = constructor!
2779+
return this[Strings.fromFloat32Array].function!(this: this, arguments: [_toJSValue(array32)]).fromJSValue()!
2780+
}
27772781

2778-
// XXX: illegal static override
2779-
// override public class func fromFloat64Array(array64: Float64Array) -> Self
2782+
@inlinable override public class func fromFloat64Array(array64: Float64Array) -> Self {
2783+
let this = constructor!
2784+
return this[Strings.fromFloat64Array].function!(this: this, arguments: [_toJSValue(array64)]).fromJSValue()!
2785+
}
27802786

27812787
@usableFromInline let _a: ReadWriteAttribute<Double>
27822788
@inlinable override public var a: Double {
@@ -3377,8 +3383,10 @@ public class DOMPoint: DOMPointReadOnly {
33773383
self.init(unsafelyWrapping: Self.constructor!.new(arguments: [_toJSValue(x), _toJSValue(y), _toJSValue(z), _toJSValue(w)]))
33783384
}
33793385

3380-
// XXX: illegal static override
3381-
// override public class func fromPoint(other: DOMPointInit? = nil) -> Self
3386+
@inlinable override public class func fromPoint(other: DOMPointInit? = nil) -> Self {
3387+
let this = constructor!
3388+
return this[Strings.fromPoint].function!(this: this, arguments: [_toJSValue(other)]).fromJSValue()!
3389+
}
33823390

33833391
@usableFromInline let _x: ReadWriteAttribute<Double>
33843392
@inlinable override public var x: Double {
@@ -3577,8 +3585,10 @@ public class DOMRect: DOMRectReadOnly {
35773585
self.init(unsafelyWrapping: Self.constructor!.new(arguments: [_toJSValue(x), _toJSValue(y), _toJSValue(width), _toJSValue(height)]))
35783586
}
35793587

3580-
// XXX: illegal static override
3581-
// override public class func fromRect(other: DOMRectInit? = nil) -> Self
3588+
@inlinable override public class func fromRect(other: DOMRectInit? = nil) -> Self {
3589+
let this = constructor!
3590+
return this[Strings.fromRect].function!(this: this, arguments: [_toJSValue(other)]).fromJSValue()!
3591+
}
35823592

35833593
@usableFromInline let _x: ReadWriteAttribute<Double>
35843594
@inlinable override public var x: Double {

Sources/WebIDLToSwift/WebIDL+SwiftRepresentation.swift

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,8 @@ extension IDLOperation: SwiftRepresentable, Initializable {
481481
if returnType == ModuleState.className {
482482
returnType = "Self"
483483
}
484-
if ModuleState.override, ModuleState.static {
485-
return """
486-
// XXX: illegal static override
487-
// \(nameAndParams) -> \(returnType)
488-
"""
484+
if ModuleState.override, ModuleState.static, !ModuleState.inClass {
485+
preconditionFailure("Cannot override static method in non-class")
489486
}
490487

491488
let (prep, call) = defaultBody
@@ -527,11 +524,8 @@ extension AsyncOperation: SwiftRepresentable, Initializable {
527524
}
528525

529526
var defaultRepresentation: SwiftSource {
530-
if ModuleState.override, ModuleState.static || operation.special == "static" {
531-
return """
532-
// XXX: illegal static override
533-
// \(operation.nameAndParams) async -> \(returnType)
534-
"""
527+
if ModuleState.override, ModuleState.static || operation.special == "static", !ModuleState.inClass {
528+
preconditionFailure("Cannot override static method in non-class")
535529
}
536530

537531
let (prep, call) = operation.defaultBody

0 commit comments

Comments
 (0)