Skip to content

Commit

Permalink
[null-safety] remove implicit-dynamic, intl in preparation for null-s…
Browse files Browse the repository at this point in the history
…afety (dart-lang/file#160)

- Implicit dynamic is removed, which will make it easier to migrate to null-safety where it is not supported.
- Intl dependency is removed, since this will block null safety despite being used in only a single place.
  • Loading branch information
jonahwilliams authored Jul 29, 2020
1 parent c9dd585 commit 1f0ab00
Show file tree
Hide file tree
Showing 35 changed files with 160 additions and 142 deletions.
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
errors:
# treat missing required parameters as a warning (not a hint)
Expand All @@ -8,10 +9,6 @@ analyzer:
missing_return: warning
# allow having TODOs in the code
todo: ignore
# Ignore analyzer hints for updating pubspecs when using Future or
# Stream and not importing dart:async
# Please see https://github.com/flutter/flutter/pull/24528 for details.
sdk_version_async_exported_from_core: ignore

linter:
rules:
Expand Down
2 changes: 2 additions & 0 deletions pkgs/file/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Fixed more test flakiness.
* Enabled more tests.
* Internal cleanup.
* Remove implicit dynamic in preparation for null safety.
* Remove dependency on Intl

#### 5.2.1

Expand Down
4 changes: 2 additions & 2 deletions pkgs/file/lib/src/backends/chroot/chroot_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
bool recursive = false,
bool followLinks = true,
}) {
Directory delegate = this.delegate;
Directory delegate = this.delegate as Directory;
String dirname = delegate.path;
return delegate
.list(recursive: recursive, followLinks: followLinks)
Expand All @@ -149,7 +149,7 @@ class _ChrootDirectory extends _ChrootFileSystemEntity<Directory, io.Directory>
bool recursive = false,
bool followLinks = true,
}) {
Directory delegate = this.delegate;
Directory delegate = this.delegate as Directory;
String dirname = delegate.path;
return delegate
.listSync(recursive: recursive, followLinks: followLinks)
Expand Down
2 changes: 1 addition & 1 deletion pkgs/file/lib/src/backends/chroot/chroot_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class _ChrootFile extends _ChrootFileSystemEntity<File, io.File>

@override
Stream<Uint8List> openRead([int start, int end]) =>
getDelegate(followLinks: true).openRead(start, end);
getDelegate(followLinks: true).openRead(start, end).cast<Uint8List>();

@override
IOSink openWrite({
Expand Down
4 changes: 2 additions & 2 deletions pkgs/file/lib/src/backends/chroot/chroot_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ class ChrootFileSystem extends FileSystem {
case FileSystemEntityType.directory:
break;
case FileSystemEntityType.notFound:
throw common.noSuchFileOrDirectory(path);
throw common.noSuchFileOrDirectory(path as String);
default:
throw common.notADirectory(path);
throw common.notADirectory(path as String);
}
assert(() {
p.Context ctx = delegate.path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ abstract class _ChrootFileSystemEntity<T extends FileSystemEntity,

@override
Directory wrapDirectory(io.Directory delegate) =>
_ChrootDirectory.wrapped(fileSystem, delegate, relative: !isAbsolute);
_ChrootDirectory.wrapped(fileSystem, delegate as Directory,
relative: !isAbsolute);

@override
File wrapFile(io.File delegate) =>
Expand Down
2 changes: 1 addition & 1 deletion pkgs/file/lib/src/backends/memory/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ typedef PathGenerator = dynamic Function();
/// Throws a `FileSystemException` if [object] is null.
void checkExists(Object object, PathGenerator path) {
if (object == null) {
throw common.noSuchFileOrDirectory(path());
throw common.noSuchFileOrDirectory(path() as String);
}
}
15 changes: 9 additions & 6 deletions pkgs/file/lib/src/backends/memory/memory_directory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class MemoryDirectory extends MemoryFileSystemEntity
String fullPath = fileSystem.path.join(path, prefix);
String dirname = fileSystem.path.dirname(fullPath);
String basename = fileSystem.path.basename(fullPath);
DirectoryNode node = fileSystem.findNode(dirname);
DirectoryNode node = fileSystem.findNode(dirname) as DirectoryNode;
checkExists(node, () => dirname);
utils.checkIsDir(node, () => dirname);
int _tempCounter = _systemTempCounter[fileSystem] ?? 0;
Expand All @@ -99,14 +99,14 @@ class MemoryDirectory extends MemoryFileSystemEntity
throw common.directoryNotEmpty(newPath);
}
},
);
) as Directory;

@override
Directory get parent =>
(backingOrNull?.isRoot ?? false) ? this : super.parent;

@override
Directory get absolute => super.absolute;
Directory get absolute => super.absolute as Directory;

@override
Stream<FileSystemEntity> list({
Expand All @@ -123,7 +123,7 @@ class MemoryDirectory extends MemoryFileSystemEntity
bool recursive = false,
bool followLinks = true,
}) {
DirectoryNode node = backing;
DirectoryNode node = backing as DirectoryNode;
List<FileSystemEntity> listing = <FileSystemEntity>[];
List<_PendingListTask> tasks = <_PendingListTask>[
_PendingListTask(
Expand All @@ -139,7 +139,9 @@ class MemoryDirectory extends MemoryFileSystemEntity
task.dir.children.forEach((String name, Node child) {
Set<LinkNode> breadcrumbs = Set<LinkNode>.from(task.breadcrumbs);
String childPath = fileSystem.path.join(task.path, name);
while (followLinks && utils.isLink(child) && breadcrumbs.add(child)) {
while (followLinks &&
utils.isLink(child) &&
breadcrumbs.add(child as LinkNode)) {
Node referent = (child as LinkNode).referentOrNull;
if (referent != null) {
child = referent;
Expand All @@ -148,7 +150,8 @@ class MemoryDirectory extends MemoryFileSystemEntity
if (utils.isDirectory(child)) {
listing.add(MemoryDirectory(fileSystem, childPath));
if (recursive) {
tasks.add(_PendingListTask(child, childPath, breadcrumbs));
tasks.add(_PendingListTask(
child as DirectoryNode, childPath, breadcrumbs));
}
} else if (utils.isLink(child)) {
listing.add(MemoryLink(fileSystem, childPath));
Expand Down
21 changes: 12 additions & 9 deletions pkgs/file/lib/src/backends/memory/memory_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
if (node == null) {
node = _doCreate();
} else {
node = utils.isLink(node) ? utils.resolveLinks(node, () => path) : node;
node = utils.isLink(node)
? utils.resolveLinks(node as LinkNode, () => path)
: node;
utils.checkType(expectedType, node.type, () => path);
}
return node;
return node as FileNode;
}

@override
Expand Down Expand Up @@ -87,14 +89,14 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
: common.isADirectory(path);
}
},
);
) as File;

@override
Future<File> copy(String newPath) async => copySync(newPath);

@override
File copySync(String newPath) {
FileNode sourceNode = resolvedBacking;
FileNode sourceNode = resolvedBacking as FileNode;
fileSystem.findNode(
newPath,
segmentVisitor: (
Expand All @@ -108,7 +110,8 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
if (child != null) {
if (utils.isLink(child)) {
List<String> ledger = <String>[];
child = utils.resolveLinks(child, () => newPath, ledger: ledger);
child = utils.resolveLinks(child as LinkNode, () => newPath,
ledger: ledger);
checkExists(child, () => newPath);
parent = child.parent;
childName = ledger.last;
Expand All @@ -134,7 +137,7 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
int lengthSync() => (resolvedBacking as FileNode).size;

@override
File get absolute => super.absolute;
File get absolute => super.absolute as File;

@override
Future<DateTime> lastAccessed() async => lastAccessedSync();
Expand All @@ -148,7 +151,7 @@ class MemoryFile extends MemoryFileSystemEntity implements File {

@override
void setLastAccessedSync(DateTime time) {
FileNode node = resolvedBacking;
FileNode node = resolvedBacking as FileNode;
node.accessed = time.millisecondsSinceEpoch;
}

Expand All @@ -164,7 +167,7 @@ class MemoryFile extends MemoryFileSystemEntity implements File {

@override
void setLastModifiedSync(DateTime time) {
FileNode node = resolvedBacking;
FileNode node = resolvedBacking as FileNode;
node.modified = time.millisecondsSinceEpoch;
}

Expand All @@ -187,7 +190,7 @@ class MemoryFile extends MemoryFileSystemEntity implements File {
@override
Stream<Uint8List> openRead([int start, int end]) {
try {
FileNode node = resolvedBacking;
FileNode node = resolvedBacking as FileNode;
Uint8List content = node.content;
if (start != null) {
content = end == null
Expand Down
9 changes: 5 additions & 4 deletions pkgs/file/lib/src/backends/memory/memory_file_system.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class _MemoryFileSystem extends FileSystem
/// Gets the node backing for the current working directory. Note that this
/// can return null if the directory has been deleted or moved from under our
/// feet.
DirectoryNode get _current => findNode(cwd);
DirectoryNode get _current => findNode(cwd) as DirectoryNode;

@override
Node findNode(
Expand Down Expand Up @@ -248,10 +248,11 @@ class _MemoryFileSystem extends FileSystem
if (segmentVisitor != null) {
child = segmentVisitor(directory, basename, child, i, finalSegment);
}
child = utils.resolveLinks(child, subpath, ledger: pathWithSymlinks);
child = utils.resolveLinks(child as LinkNode, subpath,
ledger: pathWithSymlinks);
} else {
child = utils.resolveLinks(
child,
child as LinkNode,
subpath,
ledger: pathWithSymlinks,
tailVisitor: (DirectoryNode parent, String childName, Node child) {
Expand All @@ -266,7 +267,7 @@ class _MemoryFileSystem extends FileSystem
if (i < finalSegment) {
checkExists(child, subpath);
utils.checkIsDir(child, subpath);
directory = child;
directory = child as DirectoryNode;
}
}
return child;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ abstract class MemoryFileSystemEntity implements FileSystemEntity {
@protected
Node get resolvedBacking {
Node node = backing;
node = utils.isLink(node) ? utils.resolveLinks(node, () => path) : node;
node = utils.isLink(node)
? utils.resolveLinks(node as LinkNode, () => path)
: node;
utils.checkType(expectedType, node.type, () => path);
return node;
}
Expand Down Expand Up @@ -262,7 +264,7 @@ abstract class MemoryFileSystemEntity implements FileSystemEntity {
utils.checkType(expectedType, child.type, () => newPath);
}
if (validateOverwriteExistingEntity != null) {
validateOverwriteExistingEntity(child);
validateOverwriteExistingEntity(child as T);
}
parent.children.remove(childName);
}
Expand Down
4 changes: 2 additions & 2 deletions pkgs/file/lib/src/backends/memory/memory_link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MemoryLink extends MemoryFileSystemEntity implements Link {
: common.invalidArgument(newPath);
}
},
);
) as Link;

@override
Future<Link> create(String target, {bool recursive = false}) async {
Expand Down Expand Up @@ -99,7 +99,7 @@ class MemoryLink extends MemoryFileSystemEntity implements Link {
}

@override
Link get absolute => super.absolute;
Link get absolute => super.absolute as Link;

@override
@protected
Expand Down
14 changes: 7 additions & 7 deletions pkgs/file/lib/src/backends/memory/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef TypeChecker = void Function(Node node);
/// Throws a [io.FileSystemException] if [node] is not a directory.
void checkIsDir(Node node, PathGenerator path) {
if (!isDirectory(node)) {
throw common.notADirectory(path());
throw common.notADirectory(path() as String);
}
}

Expand All @@ -39,12 +39,12 @@ void checkType(
if (expectedType != actualType) {
switch (expectedType) {
case FileSystemEntityType.directory:
throw common.notADirectory(path());
throw common.notADirectory(path() as String);
case FileSystemEntityType.file:
assert(actualType == FileSystemEntityType.directory);
throw common.isADirectory(path());
throw common.isADirectory(path() as String);
case FileSystemEntityType.link:
throw common.invalidArgument(path());
throw common.invalidArgument(path() as String);
default:
// Should not happen
throw AssertionError();
Expand Down Expand Up @@ -89,9 +89,9 @@ Node resolveLinks(

Node node = link;
while (isLink(node)) {
link = node;
if (!breadcrumbs.add(node)) {
throw common.tooManyLevelsOfSymbolicLinks(path());
link = node as LinkNode;
if (!breadcrumbs.add(link)) {
throw common.tooManyLevelsOfSymbolicLinks(path() as String);
}
if (ledger != null) {
if (link.fs.path.isAbsolute(link.target)) {
Expand Down
Loading

0 comments on commit 1f0ab00

Please sign in to comment.