Skip to content

Commit 211d132

Browse files
authored
Don't double wrap nullable records (#3608)
1 parent c7473e4 commit 211d132

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/src/render/element_type_renderer.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ class RecordElementTypeRendererHtml
124124
.renderLinkedFields(elementType)
125125
.trim())
126126
..write(')');
127-
return wrapNullabilityParens(elementType, buffer.toString());
127+
if (elementType.nullabilitySuffix.isNotEmpty) {
128+
buffer.write(elementType.nullabilitySuffix);
129+
}
130+
return buffer.toString();
128131
}
129132

130133
@override

test/record_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ void f(() r) {}
3434
expect(recordType.nameWithGenerics, equals('Record'));
3535
}
3636

37+
void test_nullableReturn() async {
38+
var library = await bootPackageWithLibrary('''
39+
(int)? f() {}
40+
''');
41+
var fFunction = library.functions.named('f');
42+
var recordType = fFunction.modelType.returnType;
43+
expect(recordType.linkedName, matchesCompressed(r'''
44+
\(
45+
<span class="field">
46+
<span class="type-annotation">
47+
<a href=".*/dart-core/int-class.html">int</a>
48+
</span>
49+
</span>
50+
\)?
51+
'''));
52+
expect(recordType.nameWithGenerics, equals('Record?'));
53+
}
54+
3755
void test_onePositionalField() async {
3856
var library = await bootPackageWithLibrary('''
3957
void f((int) r) {}

0 commit comments

Comments
 (0)