Skip to content
This repository was archived by the owner on Aug 17, 2018. It is now read-only.

Commit 8e2937c

Browse files
committed
Disable implicit downcasts
Make the code safer. Context: dart-lang/sdk#30392
1 parent 4b4e4fb commit 8e2937c

28 files changed

+47
-47
lines changed

.analysis_options

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
analyzer:
2-
strong-mode: true
2+
strong-mode:
3+
implicit-casts: false
34
exclude:
45
- drivedump/**
56
linter:
@@ -40,4 +41,4 @@ linter:
4041
- unnecessary_brace_in_string_interp
4142
- unnecessary_getters_setters
4243
- unrelated_type_equality_checks
43-
- valid_regexps
44+
- valid_regexps

lib/fractal_stories/action.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Iterable<EnemyTargetAction> generateEnemyTargetActions(
3636
/// an [actor] and a [builder].
3737
Iterable<ExitAction> generateExitActions(
3838
Actor actor, WorldState world, ExitActionBuilder builder) sync* {
39-
RoomRoamingSituation situation = world.currentSituation;
39+
final situation = world.currentSituation as RoomRoamingSituation;
4040
var room = world.getRoomByName(situation.currentRoomName);
4141

4242
for (var exit in room.exits) {
@@ -50,7 +50,7 @@ Iterable<ExitAction> generateExitActions(
5050
/// an [actor] and a [builder].
5151
Iterable<ItemAction> generateItemActions(
5252
Actor actor, WorldState world, ItemActionBuilder builder) sync* {
53-
FightSituation situation = world.currentSituation;
53+
final situation = world.currentSituation as FightSituation;
5454

5555
for (var item in situation.droppedItems) {
5656
var action = builder(item);
@@ -248,11 +248,11 @@ abstract class Action {
248248
..wasAggressive = isAggressive
249249
..wasProactive = isProactive;
250250
if (this is EnemyTargetAction) {
251-
EnemyTargetAction action = this;
251+
final action = this as EnemyTargetAction;
252252
builder.sufferers.add(action.enemy.id);
253253
}
254254
if (this is ExitAction) {
255-
ExitAction action = this;
255+
final action = this as ExitAction;
256256
builder.dataString = action.exit.destinationRoomName;
257257
}
258258
return builder;

lib/fractal_stories/actor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ abstract class Actor extends Object
199199
for (var item in items) {
200200
if (item is! Weapon) continue;
201201
if (item.value > value) {
202-
best = item;
202+
best = item as Weapon;
203203
value = item.value;
204204
}
205205
}

lib/fractal_stories/looped_event/looped_event.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract class LoopedEvent /*TODO: implements Saveable ?*/ {
7373
return;
7474
}
7575

76-
while (!finished && _choices.isEmpty && _stringBuffer.isEmpty) {
76+
while (!finished && _choices.isEmpty as bool && _stringBuffer.isEmpty) {
7777
await update();
7878
}
7979

lib/fractal_stories/world.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class WorldState {
184184

185185
Actor getActorById(int id) {
186186
assert(actors.where((actor) => actor.id == id).length > 0,
187-
"No actor of id=$id in world: $this.");
187+
"No actor of id=$id in world: $this.");
188188
assert(actors.where((actor) => actor.id == id).length < 2,
189189
"Too many actors of id=$id in world: $this.");
190190
return actors.singleWhere((actor) => actor.id == id);

lib/src/fight/actions/disarm_kick.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class DisarmKick extends EnemyTargetAction {
6767
s.add("<owner's> <subject> fl<ies> away",
6868
subject: enemy.currentWeapon, owner: enemy);
6969
});
70-
FightSituation situation = w.currentSituation;
70+
final situation = w.currentSituation as FightSituation;
7171
w.replaceSituationById(
7272
situation.id,
7373
situation.rebuild((FightSituationBuilder b) =>

lib/src/fight/actions/pass.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ class Pass extends Action {
2424
@override
2525
final Resource rerollResource = null;
2626

27-
2827
@override
2928
String get command => "Stand off.";
3029

lib/src/fight/actions/start_slash_out_of_balance.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,15 @@ EnemyTargetAction startSlashOutOfBalancePlayerBuilder(Actor enemy) =>
6363
(a, w, enemy) => new SlashSituation.initialized(a, enemy),
6464
(a, w, enemy) => new SlashDefenseSituation.initialized(a, enemy,
6565
predeterminedResult: Predetermination.failureGuaranteed),
66-
enemy,
67-
successChanceGetter: (a, w, enemy) {
68-
// This is intentional. Since the action can only lead to either
69-
// complete miss (attacker's failure) or guaranteed failure
70-
// of enemy's defense (attacker's success), we do need to count
71-
// defender's shield here. Let's say the attacking player tries
72-
// not to hit the shield and therefore misses completely.
73-
final shieldPenalty = enemy.currentShield != null ? 0.2 : 0.0;
74-
return 0.5 - shieldPenalty;
75-
},
66+
enemy, successChanceGetter: (a, w, enemy) {
67+
// This is intentional. Since the action can only lead to either
68+
// complete miss (attacker's failure) or guaranteed failure
69+
// of enemy's defense (attacker's success), we do need to count
70+
// defender's shield here. Let's say the attacking player tries
71+
// not to hit the shield and therefore misses completely.
72+
final shieldPenalty = enemy.currentShield != null ? 0.2 : 0.0;
73+
return 0.5 - shieldPenalty;
74+
},
7675
applyStartOfFailure: startSlashOutOfBalanceApplyFailure,
7776
buildSituationsOnFailure: false);
7877

lib/src/fight/actions/take_dropped_shield.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class TakeDroppedShield extends ItemAction {
3939

4040
@override
4141
String applySuccess(Actor a, WorldState w, Storyline s) {
42-
FightSituation situation = w.currentSituation;
42+
final situation = w.currentSituation as FightSituation;
4343
w.replaceSituationById(
4444
situation.id,
4545
situation.rebuild(

lib/src/fight/actions/take_dropped_weapon.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class TakeDroppedWeapon extends ItemAction {
4242

4343
@override
4444
String applySuccess(Actor a, WorldState w, Storyline s) {
45-
FightSituation situation = w.currentSituation;
45+
final situation = w.currentSituation as FightSituation;
4646
w.replaceSituationById(
4747
situation.id,
4848
situation.rebuild(
@@ -70,7 +70,7 @@ class TakeDroppedWeapon extends ItemAction {
7070
// TODO: remove the next condition
7171
if (item is Spear) return false;
7272
if (!a.canWield) return false;
73-
Weapon weapon = item;
73+
final weapon = item as Weapon;
7474
final isSwordForSpear = a.currentWeapon is Spear && weapon is Sword;
7575
if (weapon.value <= a.currentWeapon.value && !isSwordForSpear) return false;
7676
var disarmedRecency = w.timeSinceLastActionRecord(

0 commit comments

Comments
 (0)