Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seal FileSystemEntity. #52273

Closed
modulovalue opened this issue May 5, 2023 · 3 comments
Closed

Seal FileSystemEntity. #52273

modulovalue opened this issue May 5, 2023 · 3 comments
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug

Comments

@modulovalue
Copy link
Contributor

modulovalue commented May 5, 2023

Similar to #52027 and #51912, could FileSystemEntity also be sealed so that functions like:

Z matchFileSystemEntity<Z>({
  required final FileSystemEntity entity,
  required final Z Function(Directory) directory,
  required final Z Function(File) file,
  required final Z Function(Link) link,
}) {
  if (entity is Directory) {
    return directory(entity);
  } else if (entity is File) {
    return file(entity);
  } else if (entity is Link) {
    return link(entity);
  } else {
    throw Exception(
      "Invalid state. " + entity.toString() + " was expected to be a directory, file or link.",
    );
  }
}

can be replaced with exhaustive switches?

@lrhn lrhn added area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug labels May 5, 2023
@modulovalue
Copy link
Contributor Author

FileSystemEntityType.notFound seems to imply that sealing FileSystemEntity in a way where it only has 3 variants (File, Directory & Link) is not possible and would require a fourth variant e.g. "UnknownFileSystemEntity"?

@sortie
Copy link
Contributor

sortie commented May 8, 2023

Note how there's a number of file types that exist but that Dart doesn't really support, such as block devices and character devices. It's a bad idea to write code that exhaustively consider file types.

@brianquinlan
Copy link
Contributor

This isn't really practical because there is a lot of code that extends or implements FileSystemEntity (or it's subclasses) for testing purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-io type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants