Skip to content

Instantly share code, notes, and snippets.

View osa1's full-sized avatar

Ömer Sinan Ağacan osa1

View GitHub Profile
@osa1
osa1 / main.dart
Last active January 26, 2023 15:52
Strange Dart 9 (2)
import 'my_library.dart';
// Same class B in Strange Dart 9.1, but this time it's accepted.
class B implements A {}
void main() {
wat(B()); // _a getters and setters redirect to noSuchMethod
}
@osa1
osa1 / main.dart
Last active January 26, 2023 15:48
Strange Dart 9 (1)
// Private members are not part of a class's interface, but implementing
// classes need to implement them.
//
// ... except when the class being implemented is in a separate library. See
// the second part: https://gist.github.com/osa1/a6b70f36d1041996c3ff7fa12c7589d8
class A {
int _a = 1;
int _b = 2;
@osa1
osa1 / main.dart
Last active January 24, 2023 17:35
Strange Dart 8
class A {
@override
Type get runtimeType => int;
}
class B<T> {}
void main() {
print(A().runtimeType); // int
print(B<A>().runtimeType); // B<A>
@osa1
osa1 / main.dart
Last active January 20, 2023 09:43
Strange Dart 7
// Almost by definition, if I'm able to pass X where Y is expected, then X is a
// subtype of Y.
//
// In Dart, this mostly holds, but `dynamic` is an exception. I can pass
// `dynamic` everywhere, but it's not really a subtype of anything.
void f(int a) {}
class C<A> {}
@osa1
osa1 / Lexer.hs
Created August 29, 2012 05:03
separated lexing and parsing stages in parsec
module Lexer
( Token(..)
, TokenPos
, tokenize
) where
import Text.ParserCombinators.Parsec hiding (token, tokens)
import Control.Applicative ((<*), (*>), (<$>), (<*>))
data Token = Ide String
@osa1
osa1 / main.dart
Created December 20, 2022 19:05
Strange Dart 5
class C {
dynamic get a {
print('C.a getter called');
return (x) => print('C.a return value called');
}
}
void main() {
var x = C();
@osa1
osa1 / main.dart
Last active November 30, 2022 13:33
Strange Dart 4
class A {
void f() {
print('A.f called');
}
}
class B implements A {
void f({int test}); // optional non-nullable with no default value, also not a valid override
// `f` above is not valid without a `noSuchMethod`
@osa1
osa1 / main.dart
Created November 19, 2022 09:26
Strange Dart 3
class A {
void f() {}
}
extension B on A {
void g() {}
}
void main() {
final a = A();
@osa1
osa1 / main.dart
Created November 11, 2022 20:01
Strange Dart 2
class A {
void f() {
print('A.f called');
}
}
class B extends A {
@override
void f();
}
@osa1
osa1 / main.dart
Created November 11, 2022 19:57
Strange Dart 1
void voidFun() => 123;
class A<T> {
T x;
A (this.x);
Object? getX() => x;
}