-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ffigen] Fix method vs getter conflicts (#1707)
- Loading branch information
1 parent
b4f2364
commit f0ba80c
Showing
7 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
pkgs/ffigen/test/native_objc_test/bad_override_config.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: BadOverrideTestObjCLibrary | ||
description: 'Tests various overrides that are valid in ObjC but invalid in Dart' | ||
language: objc | ||
output: 'bad_override_bindings.dart' | ||
exclude-all-by-default: true | ||
objc-interfaces: | ||
include: | ||
- BadOverrideGrandparent | ||
- BadOverrideParent | ||
- BadOverrideUncle | ||
- BadOverrideAunt | ||
- BadOverrideChild | ||
- BadOverrideSibbling | ||
- BadOverrideGrandchild | ||
headers: | ||
entry-points: | ||
- 'bad_override_test.m' | ||
preamble: | | ||
// ignore_for_file: camel_case_types, non_constant_identifier_names, unnecessary_non_null_assertion, unused_element, unused_field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// Objective C support is only available on mac. | ||
@TestOn('mac-os') | ||
|
||
import 'dart:ffi'; | ||
import 'dart:io'; | ||
|
||
import 'package:ffi/ffi.dart'; | ||
import 'package:test/test.dart'; | ||
import '../test_utils.dart'; | ||
import 'bad_override_bindings.dart'; | ||
import 'util.dart'; | ||
|
||
void main() { | ||
group('bad overrides', () { | ||
setUpAll(() { | ||
// TODO(https://github.com/dart-lang/native/issues/1068): Remove this. | ||
DynamicLibrary.open('../objective_c/test/objective_c.dylib'); | ||
final dylib = File('test/native_objc_test/objc_test.dylib'); | ||
verifySetupFile(dylib); | ||
DynamicLibrary.open(dylib.absolute.path); | ||
generateBindingsForCoverage('bad_override'); | ||
}); | ||
|
||
test('Method vs getter', () { | ||
// In ObjC, supertypes and subtypes can have a method that's an ordinary | ||
// method in some classes of the heirarchy, and a property in others. This | ||
// isn't allowed in Dart, so we change all such conflicts to properties. | ||
// https://github.com/dart-lang/native/issues/1220 | ||
expect(BadOverrideParent.new1().methodVsGetter, 1); | ||
expect(BadOverrideChild.new1().methodVsGetter, 11); | ||
expect(BadOverrideSibbling.new1().methodVsGetter, 12); | ||
expect(BadOverrideGrandchild.new1().methodVsGetter, 111); | ||
|
||
var inst = BadOverrideParent.new1(); | ||
expect(inst.methodVsGetter, 1); | ||
inst = BadOverrideChild.new1(); | ||
expect(inst.methodVsGetter, 11); | ||
inst = BadOverrideSibbling.new1(); | ||
expect(inst.methodVsGetter, 12); | ||
inst = BadOverrideGrandchild.new1(); | ||
expect(inst.methodVsGetter, 111); | ||
|
||
// Uncle isn't affected by the transform, so has an ordinary method. | ||
expect(BadOverrideUncle.new1().methodVsGetter(), 2); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
#import <Foundation/NSObject.h> | ||
|
||
@interface BadOverrideGrandparent : NSObject {} | ||
@end | ||
@implementation BadOverrideGrandparent | ||
@end | ||
|
||
@interface BadOverrideParent : BadOverrideGrandparent {} | ||
-(int32_t)methodVsGetter; | ||
@property (readonly) int32_t methodVsGetter; | ||
@end | ||
@implementation BadOverrideParent | ||
-(int32_t)methodVsGetter { return 1; } | ||
@end | ||
|
||
@interface BadOverrideUncle : BadOverrideGrandparent {} | ||
-(int32_t)methodVsGetter; | ||
@end | ||
@implementation BadOverrideUncle | ||
-(int32_t)methodVsGetter { return 2; } | ||
@end | ||
|
||
@interface BadOverrideAunt : BadOverrideGrandparent {} | ||
@end | ||
@implementation BadOverrideAunt | ||
@end | ||
|
||
@interface BadOverrideChild : BadOverrideParent {} | ||
@property (readonly) int32_t methodVsGetter; | ||
@end | ||
@implementation BadOverrideChild | ||
-(int32_t)methodVsGetter { return 11; } | ||
@end | ||
|
||
@interface BadOverrideSibbling : BadOverrideParent {} | ||
-(int32_t)methodVsGetter; | ||
@end | ||
@implementation BadOverrideSibbling | ||
-(int32_t)methodVsGetter { return 12; } | ||
@end | ||
|
||
@interface BadOverrideGrandchild : BadOverrideParent {} | ||
-(int32_t)methodVsGetter; | ||
@end | ||
@implementation BadOverrideGrandchild | ||
-(int32_t)methodVsGetter { return 111; } | ||
@end |