question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(dev2.0) Inherited type constructor issue

See original GitHub issue

This is compiling just fine with the master branch, but not in dev2.0:

open System.Collections.Generic

type ConcurrentDictionary<'TKey, 'TValue when 'TKey: equality> =
    inherit Dictionary<'TKey, 'TValue>
    new () = { inherit Dictionary<'TKey, 'TValue>() }
    new (comparer: IEqualityComparer<'TKey>) = { inherit Dictionary<'TKey, 'TValue>(comparer) }
    member x.TryAdd (key:'TKey, value:'TValue) = x.[key] <- value; true

Here is the result, the constructors are messed up, the return is not in the right place:

import { tryGetValue, comparerFromEqualityComparer } from "./fable-core.2.0.0-alpha-020/Util";
import { createMutable } from "./fable-core.2.0.0-alpha-020/Map";
export function ConcurrentDictionary$00602$$$$002Ector() {
  new Map([]);
  return new ConcurrentDictionary$00602();
}
export function ConcurrentDictionary$00602$$$$002Ector$$1(comparer) {
  createMutable([], comparerFromEqualityComparer(comparer));
  return new ConcurrentDictionary$00602();
}
export function ConcurrentDictionary$00602$$TryAdd(x, key, value) {
  x.set(key, value);
  return true;
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ncavecommented, Jun 28, 2018

Closing as the suggested alternative seems to work.

1reaction
alfonsogarciacarocommented, Jun 20, 2018

Hmm, the REPL gives me something like this:

export class ConcurrentDictionary extends Map {
  static [".ctor_0"]() {
    new Map();
    return new ConcurrentDictionary();
  }

  static [".ctor_1"](comparer) {
    create(null, fromEqualityComparer(comparer));
    return new ConcurrentDictionary();
  }

  TryAdd(key, value) {
    this.set(key, value);
    return true;
  }
}

Probably this is working due to a happy coincidence of not compiling to ES5, using a JS engine that accepts inheritance from native types with classes, and the autogeneration of the class constructor. But the secondary constructors look faulty, and this will definitely not work with a custom comparer 😕

Read more comments on GitHub >

github_iconTop Results From Across the Web

Delphi XE2 - Inheriting class not calling base ...
When creating a class that inherits from another class, shouldn't it be true that when the derived class is created the base classes's ......
Read more >
c++ - Why are constructors not inherited?
There can't be any proper inheritance of constructors in C ++, because the constructor of a derived class needs to perform additional actions ......
Read more >
CHANGES — automaton 1.7.2.dev2 documentation
1.2.0¶. Add a state-space machine building example; Ensure state space can also pass on_enter/exit callbacks; Updated from global requirements ...
Read more >
Problems with overriding and template function
I've tried using a virtual function in the base class to access ... ftree(void) {name[0] = parent[0] = child[0] = 0;} // default...
Read more >
SYCL™ 2020 Specification (revision 7) - Khronos Registry
The terminology used for SYCL inherits historically from OpenCL with some ... Type T has at least one eligible copy constructor, move constructor, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found