Comments (3)
Updated @ f881fbe, much less repetitions, but still some
from typeprof.
The
Array[Integer]
should clearly not be repeated.
Agreed, it is a bug depending on very subtle internal. I'll try fixing it tomorrow.
Detail: In general, TypeProf deals with Foo[X]
(a class with a type variable) as if its instance has only one cell that contains X
. However, arrays and hashes are specially handled to track their multiple elements (i.e., not only one cell) on a best effort basis because an array is often used as a tuple and a hash is often used as a JSON record and keywords.
However, Array.new
and Hash.new
creates general instances, not specially handled (just because I have not implemented it yet). A general instance of Array
class (which should not occur) and a specially-handled array are not merged appropriately, which leads to Array[Integer] | Array[Integer]
(one is for a general instance of Array
, and the other is for a specially-handled array.)
Probably a beginner's question, but since
Array
is covariant, shouldn'tArray[Integer] | Array[untyped]
be simplified toArray[untyped]
?
Good question. In short, TypeProf merges Array[X] | Array[Y]
to Array[X | Y]
. I guess that the reason why they are not merged is what I said above.
But there are some more esoteric points:
- Currently, TypeProf does not handle variance because TypeProf's approach is very different from traditional generics system. Notably, TypeProf allows implicit type expansion:
a = [1]; p a
shows[Integer]
(an one-length array that contains one Integer), anda = [1]; a << "str"; p a
showsArray[Integer | String]
(a length-unknown array that containsInteger | String
). So, the element types of an array is not fixed in TypeProf. To support variance in TypeProf, we need a new theory (TM). - TypeProf merges
Array[X] | Array[Y]
toArray[X | Y]
blindly, regardless of variance, mainly because of the analysis performance. I know it is less precise. (Array[X] | Array[Y]
is an array containing onlyX
s, or an array containing onlyY
s. On the other hand,Array[X | Y]
is an array that may mixX
andY
.) But the distinguishment ofArray[X] | Array[Y]
led to state explosion in some experiments, so I compromised. - In theory,
X | untyped
is equal tountyped
. But unfortunately, TypeProf easily producesuntyped
for many reasons (just unimplemented feature, the limitation of analysis precision, etc.). The current goal of TypeProf is a type inference tool, and in my experience, when TypeProf saysX | untyped
, my expected result isX
. So, I think that simplifyingX | untyped
tountyped
makes TypeProf less useful. Rather, TypeProf implicitly removes| untyped
by default. (This removal can be suppressed by-fpedantic-output
option).
Anyway, thank you very much for your interest to TypeProf!
from typeprof.
All very interesting, thank you! I'll mentally delete | Array[untyped]
then.
from typeprof.
Related Issues (20)
- undefined method: singleton HOT 1
- A feature to ignore errors on a specified line
- Error message with rbs_collection HOT 7
- Updating a Rails app to Ruby 3.1.2 breaks typrof HOT 1
- Importing RBS::AST::Members::ClassInstanceVariable is not supported yet
- Typing of dynamic methods and variables
- Fail to start TypeProf for IDE on zsh
- Typeprof failed to start when rbs_collection.lock.yaml doesn't exist.
- tests not working for 0.21.7 on ruby 3.1 HOT 1
- test dependency sider/goodcheck is gone HOT 1
- Tests for version 0.21.8 are failing in ruby 3.2.2 with rbs 2.8.2
- URI require issue HOT 1
- Auto-commenting of methods doesn't handle multiple lines
- Enumerator expects 2 arguments
- Type `::Range` is generic but used as a non generic type
- Methods defined in a Struct.new block end up on parent module
- `include Enumerable` causes error
- Instance variables are sometimes incorrectly added to `Object` HOT 1
- Instance variables in subclasses sometimes are defined incorrectly HOT 2
- vscode error: typeprof running on wrong ruby HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from typeprof.