dartssh2 icon indicating copy to clipboard operation
dartssh2 copied to clipboard

Proposed change in code for the "|" operator overload in SftpFileOpenMode

Open gaddlord opened this issue 2 years ago • 0 comments

Currently we have the declaration

class SftpFileOpenMode {
  ...
 operator |(SftpFileOpenMode other) => SftpFileOpenMode._(flag | other.flag);
}

The operator overload is declared without providing the desired return type which defaults it to dynamic.

This emits an error when compiled with Dart 3.0 "The argument 'dynamic' can't be assigned to the parameter type 'SftpFileOpenMode.'" in the sample below:

final file = await sftp.open(remoteFilename, mode: SftpFileOpenMode.create | SftpFileOpenMode.write);

The way to solve that is to specify explictly the return type of the "|" operator to be SftpFileOpenMode as shown in the sample below:

class SftpFileOpenMode {
  ...
  SftpFileOpenMode operator |(SftpFileOpenMode other) => SftpFileOpenMode._(flag | other.flag);
}

gaddlord avatar May 27 '23 18:05 gaddlord