-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for overriding upstream types in eqwalizer_types.erl
Summary: Use module `eqwalizer_types` to override any upstream type, similar to how `eqwalizer_specs` is used. Reviewed By: ilya-klyuchnikov Differential Revision: D65831604 fbshipit-source-id: 4e6f1c30412d6e5f991c91e001cd81f395cc872f
- Loading branch information
1 parent
b7c5d4c
commit 759af3c
Showing
2 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
eqwalizer/src/main/scala/com/whatsapp/eqwalizer/ast/stub/CustomTypes.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* Copyright (c) Meta Platforms, Inc. and affiliates. All rights reserved. | ||
* | ||
* This source code is licensed under the Apache 2.0 license found in | ||
* the LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.whatsapp.eqwalizer.ast.stub | ||
|
||
import com.whatsapp.eqwalizer.ast.Forms.TypeDecl | ||
import com.whatsapp.eqwalizer.ast.Id | ||
|
||
private object CustomTypes { | ||
private lazy val customTypes: Map[String, Map[Id, TypeDecl]] = | ||
Db.getModuleStub("eqwalizer_types") match { | ||
case Some(stub) => | ||
stub.types.toList | ||
.map { case (id, ty) => | ||
val Array(module, tyName) = id.name.split(":") | ||
val id1 = Id(tyName, id.arity) | ||
val ty1 = ty.copy(id = id1)(ty.pos) | ||
(module, id1) -> ty1 | ||
} | ||
.groupBy { case ((module, _), _) => module } | ||
.view | ||
.mapValues(_.map { case ((_, id), ty) => id -> ty }.toMap) | ||
.toMap | ||
case None => | ||
Map.empty | ||
} | ||
|
||
def getType(module: String, id: Id): Option[TypeDecl] = | ||
for { | ||
types <- customTypes.get(module) | ||
ty <- types.get(id) | ||
} yield ty | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters